我正在运行nginx。当前设置为
main_site.local(主站点)物理路径:/var/www/html/test/testme/bla/main_site/public_html
main_site.local/lavel物理路径:/var/www/html/test/testme/bla/main.site/public_html/laravel/public
基于此:在子文件夹中为Laravel配置nginx
我有
server {
listen 81;
#listen [::]:81 default ipv6only=on; ## listen for ipv6
root /var/www/html/test/testme/bla/main_site/public_html;
index index.php index.html index.htm;
server_name main_site.local;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ^~ /laravel {
alias /var/www/html/test/testme/bla/main_site/public_html/laravel/public;
try_files $uri $uri/ @laravel;
location ~ '.php {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+'.php)(.*)$;
include /etc/nginx/fastcgi_params;
}
}
location @laravel {
rewrite /laravel/(.*)$ /laravel/index.php?/$1 last;
}
location ~ '.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+'.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
当我点击mainsite.local/lavel时,它显示的是一个空白页面,而不是laravel欢迎页面。
我在/var/www/html/test/testme/bla/main.site/public_html/laravel/public/index.php中放入了一个die,它不执行。
更新1
基于此:https://mnshankar.wordpress.com/2014/03/19/nginx-config-for-hosting-multiple-projects-in-sibling-folders/
我有
server {
listen 81;
root /var/www/html/test/testme/igloo/igloosof/public_html;
index index.html index.htm index.php app.php app_dev.php;
server_name main-site.local;
charset utf-8;
location /laravel{
rewrite ^/laravel/(.*)$ /laravel/public/index.php?$1 last;
}
location ~ '.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+'.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
错误:RouteCollection.php行161中的NotFoundHttpException我正在访问默认的laravel主页(欢迎页面)
如果您还没有解决这个问题,请尝试将fastcgi_param SCRIPT_FILENAME
添加到第一个示例的in-location->php块中。
以下是我如何设置我的location
块,它非常适合我:
location ^~ /facebookschedule {
alias /home/netcans/facebookschedule/public;
try_files $uri $uri/ @foobar;
location ~ '.php {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+'.php)(.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/wwww/facebookschedule/public/index.php;
}
}
location @foobar {
rewrite /facebookschedule/(.*)$ /facebookschedule/index.php?/$1 last;
}
我也收到了类似的White Screen(空白页)和404个与未找到的路由相关的错误,但能够按照本文中完整的Nginx Conf文件示例修复所有错误:
http://shubhank.gaur.io/setup-laravel-5-in-subfolder-with-nginx/
这可能是因为你的ngnix配置。有两种方法可以检查配置:
如果你想把你的laravel
项目放在带有ngnix-ubuntu 16-php.7.2
的服务器上的subfolder
中,那么这里是更新ngnix-config:
1) 您的嵌套(子文件夹)不在主文件夹中
/var/www/main:
/var/www/nested:
然后你的配置:
location /nested {
alias /var/www/nested/public;
try_files $uri $uri/ @nested;
location ~ '.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}
location @nested {
rewrite /nested/(.*)$ /nested/index.php?/$1 last;
}
2) 主目录中的laravel测试文件夹(子文件夹):
/var/www/main:
/var/www/main/nested:
然后你的配置:
location /laravel-test {
alias /var/www/main/laravel-test/public;
try_files $uri $uri/ @laravelTest;
location ~ '.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}
location @laravelTest {
rewrite /laravel-test/(.*)$ /laravel-test/index.php?/$1 last;
}
这是我在谷歌搜索数小时后使用Nginx 1.13和PHP-7.2得到的一个解决方案。
在这里写一篇关于将php应用程序放入子目录的完整解释。
三个重要部分是:
- 弄清楚
root
和alias
在做什么 - 使用命名的
location
块成功执行rewrite
- 找到一种不必硬编码FastCGI的
SCRIPT_FILENAME
的方法
以下是我找到的解决方案(请注意,应用程序位于磁盘驱动器的不同位置):
server {
listen 80 default_server;
root /var/www/top/public;
index index.html index.htm index.php;
server_name _;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location /nested {
alias /var/www/nested/public;
try_files $uri $uri/ @nested;
location ~ '.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
location @nested {
rewrite /nested/(.*)$ /nested/index.php?/$1 last;
}
location ~ '.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}