[英]Nginx configuration for Laravel 5.2 and PHP 7: Routes not working
我正在尝试设置一个AWS Ubuntu服务器来托管Laravel项目。 我在使路由正常工作时遇到问题,我怀疑我的Nginx虚拟主机配置文件是罪魁祸首。
我认为具体是try_files行是问题吗? 我已经尝试过try_files $uri $uri/ /index.php$is_args$args;
以及try_files $uri $uri/ /index.php?$query_string;
以及其他一些错误结果,包括:
这是我的/ etc / nginx / sites-enabled / default:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html/public;
index index.php index.html index.htm;
# Make site accessible from amazon aws
server_name xxxx.us-west-2.compute.amazonaws.com;
location / {
# Try file, then try folder, then pass to Laravel's /public/index.php
try_files $uri $uri/ /index.php$is_args$args;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
这是文件的当前状态,就像我说的那样,它当前将任何实际路由重定向到blahblah.com/index.php/
并显示Laravel欢迎页面。 尚未设置的伪造路由会在Laravel 404页面中显示。
我很沮丧,因为这里有一些指南,我已经尝试了所有可以找到的建议,所以我一定会错过一些东西。
看来php7工作正常,不是问题所在,或者这可能是php配置文件中的问题?
发展:如果我使用其IP(感谢Oliver Queen)访问该网站,似乎可以正常工作,是否知道如何在使用域名时可以使其正常工作?
将您的当前location /
替换为以下代码:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
然后将其下方的位置替换为:
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.