[英]Lumen Route redirect to 404 in Nginx
I am doing one project in lumen, and I have installed this in my LAMP server. 我正在做一个流明项目,并且已经在我的LAMP服务器中安装了这个项目。 I have use a htaccess file to strip index.php from url. 我已经使用htaccess文件从网址中删除index.php。 here is my htaccess file 这是我的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>
Here everything is working fine. 在这里一切正常。 Now I am moving my files to newly created instance with LEMP stack server (nginx). 现在,我将文件移动到使用LEMP堆栈服务器(nginx)新建的实例。 This is lumen file, so I have installed composer in my project directory. 这是流明文件,因此我已经在项目目录中安装了composer。 when I am putting a test route in url (browser), (eg: website.com/getUser) it is showing 404 page error. 当我在url(浏览器)中放置测试路由时(例如:website.com/getUser),它显示404页面错误。
SO I have modified the nginx default file in /etc/nginx/sites-available/default 所以我已经修改了/ 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;
}
}
and then I have created a separate server block file for my website by copying the default file and making some changes. 然后通过复制默认文件并进行一些更改为网站创建了一个单独的服务器阻止文件。 that file is below. 该文件在下面。
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;
}
}
Now, when I typing my url (website.com/getUser), then it is downloading something. 现在,当我输入网址(website.com/getUser)时,它正在下载内容。 after opening in sublime, I get to know that this file is actually index.php which is in root directory of my project (website.com/index.php) 崇高地打开后,我知道该文件实际上是index.php,它位于我的项目(website.com/index.php)的根目录中
I am not getting, why it is happening. 我不明白为什么会这样。 Why I am not be able to access my route. 为什么我无法访问我的路线。 Where is the problem, can you guys help me in this. 问题出在哪里,你们可以帮我吗?
Thanks in advance. 提前致谢。
Add this to your config: 将此添加到您的配置:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.