更改 Azure PHP Webrole 上的文档根目录


Change document root on azure php webrole

我想在 azure webrole 上设置 Laravel 框架,并且必须更改文档根目录,但到目前为止我找不到如何做到这一点的方法

我的部署项目文件夹:

├──webrole <- now this is document root
│  ├──app
│  ├──bin
│  ├──bootstrap
│  ├──config
│  ├──database
│  ├──public <- I want make this as document root
│  ├──resources
│  ├──storage
│  ├──tests
│  ├──vendor
│  ├──.env
│  ├──.env.example
│  ├──.gitattributes
│  ├──.gitignore
│  ├──artisan
│  ├──composer.json
│  ├──composer.lock
│  ├──gulpfile.js
│  ├──package.json
│  ├──phpspec.yml
│  ├──phpunit.xml
│  ├──readme.md
│  ├──server.php
│  ├──Web.cloud.config
│  └──Web.config
├──deploymentSettings.json
├──ServiceConfiguration.Cloud.cscfg
├──ServiceConfiguration.Local.cscfg
├──ServiceDefinition.csdef

我发现了Windows Azure WebRole的更改approot路径,但这是一个很老的问题,没有批准的答案

我发现的唯一解决方法是使用重写规则,但我认为这并不安全......

与 Azure 云服务 PHP WebRole 目录中一样,其中有用于在 IIS 上配置 PHP 站点应用程序的web.configweb.cloud.config文件。

Web 可以在这些文件中找到如下所示的内容:

<system.webServer>
    <defaultDocument>
      <files>
        <clear />
        <add value="index.php" />
      </files>
    </defaultDocument>
  </system.webServer>

我们可以修改设置defaultDocument以更改laravel应用程序的文档根目录:

<system.webServer>
    <defaultDocument>
      <files>
        <clear />
        <add value="public/index.php" />
      </files>
    </defaultDocument>
  </system.webServer>

如果有人仍在搜索答案:

您可以通过以下 2 个步骤替换 nginx 配置文件来轻松更改根目录:

1-将新的配置文件添加到您的项目根目录(wwwroot),我们称之为default

server {
#proxy_cache cache;
#proxy_cache_valid 200 1s;
listen 8080;
listen [::]:8080;
root /home/site/wwwroot/public; # changed for Laravel
index  index.php index.html index.htm;
server_name  example.com www.example.com;
location / {
    try_files $uri $uri/ /index.php?$args; # changed for Laravel
}
# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /html/;
}
# Disable .git directory
location ~ /'.git {
    deny all;
    access_log off;
    log_not_found off;
}
# Add locations of phpmyadmin here.
location ~ [^/]'.php(/|$) {
    fastcgi_split_path_info ^(.+?'.php)(|/.*)$;
    fastcgi_pass 127.0.0.1:9000;
    include fastcgi_params;
    fastcgi_param HTTP_PROXY "";
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param QUERY_STRING $query_string;
    fastcgi_intercept_errors on;
    fastcgi_connect_timeout         300;
    fastcgi_send_timeout           3600;
    fastcgi_read_timeout           3600;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
}

}

2-添加启动命令以将nginx配置文件替换为新文件。

  • 输入 Azure 资源设置 ->配置。

  • "常规设置"选项卡。

  • 启动命令:

    cp /home/site/wwwroot/default /etc/nginx/sites-available/default && service nginx reload

这应该会在每次实例启动时更改文档根目录。

资源:https://learn.microsoft.com/en-us/azure/mysql/flexible-server/tutorial-php-database-app