我正在运行nginx。目前的设置是
main_site.local(主站点) 物理路径:/ var / www / html / test / testme / bla / main_site / public_html
main_site.local / laravel 物理路径:/ var / www / html / test / testme / bla / main_site / public_html / laravel / public
基于此:Config nginx for Laravel In a subfolder
我有
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;
}
当我点击main_site.local / laravel时,它会显示一个空白页面,而不是laravel欢迎页面。
我在/var/www/html/test/testme/bla/main_site/public_html/laravel/public/index.php中放了一个骰子,它没有执行。
更新1
我有
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主页(欢迎页面)
答案 0 :(得分:4)
如果你仍然没有解决这个问题,请尝试将fastcgi_param SCRIPT_FILENAME
添加到第一个示例的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;
}
我也得到类似的白色屏幕(空白页面)和404错误相关的路线未找到但能够修复此帖子中完整的Nginx Conf文件示例后的所有内容:
http://shubhank.gaur.io/setup-laravel-5-in-subfolder-with-nginx/
答案 1 :(得分:1)
这可能是因为有关您的ngnix配置。您可以通过两种方式检查config:
如果您想将laravel
项目放在具有subfolder
的服务器上的ngnix-ubuntu 16-php.7.2
中,那么这里是update 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-test文件夹(子文件夹):
/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;
}
答案 2 :(得分:0)
这是我用谷歌搜索数小时后使用Nginx 1.13和PHP-7.2的解决方案。
putting a php app in a subdirectory here上的写作/完整说明。
三个重要部分是:
root
vs alias
正在做什么location
块来成功执行rewrite
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;
}
}