【发布时间】:2016-04-29 20:21:14
【问题描述】:
我正在尝试设置 AWS Ubuntu 服务器来托管 Laravel 项目。我在让路由正常工作时遇到问题,我怀疑我的 Nginx 虚拟主机配置文件是罪魁祸首。
我认为特别是 try_files 行是问题所在?我试过try_files $uri $uri/ /index.php$is_args$args; 和try_files $uri $uri/ /index.php?$query_string; 以及其他几个,但有几个错误的结果,包括:
- 404 错误
- 500 个错误
- 正在链接到源代码的下载
- 这是当前行为,被重定向到 /index.php/(显示 Laravel 欢迎页面)。
这是我的 /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),知道如何在使用域名时让它工作吗?
【问题讨论】:
-
我的猜测是域名不可能。
标签: php laravel nginx laravel-5.2 php-7