【发布时间】:2018-01-11 12:10:33
【问题描述】:
我正在用 lumen 做一个项目,我已经在我的 LAMP 服务器中安装了它。我使用 htaccess 文件从 url 中删除 index.php。 这是我的 htaccess 文件
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
这里一切正常。 现在我正在使用 LEMP 堆栈服务器 (nginx) 将我的文件移动到新创建的实例。这是 lumen 文件,所以我在我的项目目录中安装了 composer。 当我在 url(浏览器)中放置测试路由时(例如:website.com/getUser),它显示 404 页面错误。
所以我修改了 /etc/nginx/sites-available/default 中的 nginx 默认文件
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
#try_files $uri =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;
include snippets/fastcgi-php.conf;
# fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
然后我通过复制 default 文件并进行一些更改,为我的网站创建了一个单独的服务器块文件。该文件在下面。
server {
listen 80 ;
listen [::]:80 ;
root /var/www/html/my.website.com;
server_name my.website.com;
location / {
rewrite ^/(.*)/$ /$1 redirect;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php break;
}
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
现在,当我输入我的网址 (website.com/getUser) 时,它正在下载一些东西。在 sublime 中打开后,我知道这个文件实际上是 index.php,它位于我的项目的根目录(website.com/index.php)
我不明白,为什么会这样。为什么我无法访问我的路线。问题出在哪里,大家能帮帮我吗?
提前致谢。
【问题讨论】: