我在VM上有一个laravel应用程序,并使用nginx设置了服务器,但是每次调用路由时,它都无法正常工作,并重定向到404未找到
这是我的Nginx配置:
server {
listen 80 default_server;
listen [::]:80 default_server;
index index.html index.htm index.nginx-debian.html index.php;
server_name _;
location / {
#deny all;
try_files $uri $uri/ /index.php$is_args$args;
}
location /crm-api {
root /var/www/crm-api/public; #
rewrite ^/crm-api/(.*)$ /$1 break; #
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ /\. {
deny all;
}
location ~ \.php$ {
set $newurl $request_uri; #
if ($newurl ~ ^/crm-api(.*)$) { #
set $newurl $1; #
root /var/www/crm-api/public; #
} #
try_files $uri=404 /index.php=404;
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param REQUEST_URI $newurl; #
fastcgi_intercept_errors on;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
我创建/ crm-api是因为我想在我的vm上运行多个应用程序,我尝试了几种解决方案,但仍然无法正常工作。
答案 0 :(得分:1)
尝试使用此代码块代替您的位置代码块
location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php?$query_string;
}
希望对您有帮助。
答案 1 :(得分:-2)
这是我的配置,可以正常工作
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$query_string;
}