我在单个域的子文件夹(社交networking应用程序,需要https,单个证书)下设置多个Laravel应用程序。
无法弄清楚如何编写nginxconfiguration将HTTP请求映射到/app1/到/var/www/other_folder/public/下的Laravel安装。
这是最新的configurationtesting迭代。 debugginglogging省略。 Laravel根位置/ app1 / works,但是路由映射( /app1/api/method/ )不会。 请帮忙,如何debuggingnginx如何逐步处理请求(debugging日志是不是说明),或者给我一个提示如何映射/app1/...子文件夹到Laravel的index.php 。
server { listen 80; server_name apps.mydomain.com; root /var/www/apps.mydomain.com/docs; location / { index index.html index.php; } location /app1 { alias /var/www/other_folder/public; index index.php index.html; try_files $uri $uri/ /app1/index.php$is_args$args /app1/index.php?$query_string; } location ~ /app1/.+\.php$ { rewrite ^/app1/(.*)$ /$1 break; include /etc/nginx/fastcgi.conf; fastcgi_param SCRIPT_FILENAME /var/www/other_folder/public$fastcgi_script_name; fastcgi_index index.php; fastcgi_pass php; # Database access parameters fastcgi_param DB_HOST "localhost"; fastcgi_param DB_USER "apps"; fastcgi_param DB_PASS "xxxxxxxx"; fastcgi_param DB_NAME "app1"; } # Other locations skipped include /etc/nginx/global/php.conf; # other php scripts }
我认为你应该改变位置的根源。 根据Nginx的文档,root指令也有上下文“location”:
语法:根path;
上下文:http,服务器,位置,如果在位置
所以你应该可以做如下的事情:
server { listen 80; server_name apps.mydomain.com; root /var/www/apps.mydomain.com/docs; location / { index index.html index.php; } location /app1 { root /var/www/other_folder/public; rewrite ^/app1/(.*)$ /$1 break; index index.php index.html; try_files $uri $uri/ /index.php$is_args$args /index.php?$query_string; } location ~ /app1/.+\.php$ { root /var/www/other_folder/public; rewrite ^/app1/(.*)$ /$1 break; include /etc/nginx/fastcgi.conf; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_index index.php; fastcgi_pass php; # Database access parameters fastcgi_param DB_HOST "localhost"; fastcgi_param DB_USER "apps"; fastcgi_param DB_PASS "xxxxxxxx"; fastcgi_param DB_NAME "app1"; } # Other locations skipped include /etc/nginx/global/php.conf; # other php scripts }
据我所知,别名指令重新映射到另一个URL的URL和处理继续,它没有定义从哪里来源文件的目录。 我不确定你是否仍然需要在PHP位置重写。
此代码未经testing。 但是你说它适用于/ app1 /而不适用于/ app1 / api / method /。 我猜你的问题在于这个部分:
location /app1 { alias /var/www/other_folder/public; index index.php index.html; try_files $uri $uri/ /app1/index.php$is_args$args /app1/index.php?$query_string; }
所以这基本上告诉去尝试的url ,如果不匹配,尝试匹配它作为一个目录url/ ,如果没有文件和目录存在,那么我们尝试将其匹配为/app1/index.php?someargs ,如果它不存在,匹配它/app1/index.php?$query_string
首先, 别名和try_files不能一起工作,所以你可以使用root来代替。 将/ app1位置块更改为以下内容以查看是否修复了您的问题。
location /app1 { root /var/www/other_folder/public; index index.php index.html; try_files $uri $uri/ /index.php$is_args$args; }
其次,$ query_string和$ args是一样的,唯一的区别就是它是只读的。
就像我说的,这是没有经过testing的,但是如果它能够正常工作的话,它会很好。 如果没有,我还有一个想法。