我正在尝试使用 Nginx 设置我的 Laravel 项目。我的 /etc/nginx/conf.d/default.conf
是:
server {
listen 80;
index index.php index.html;
root /var/www/public;
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
我对以“.php”结尾的路由有疑问,例如
Route::get('modules.php', 'ModuleController@index');
服务器尝试打开不存在的文件modules.php
,而不是转到index.php并查找路由。
我知道,nginx 设置中有这个问题,但我没有这方面的经验,所以我自己无法修复它。
最佳答案
在这里您可以找到合适的配置和说明。 例如:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/laravel/public;
index index.php index.html index.htm;
server_name server_domain_or_IP;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
关于php - Laravel 项目的 Nginx 设置,该项目的路由以 ".php"结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54131616/