Laravel:如何允许具有.php文件扩展名的路由
我正在使用homestead(所以我处理Nginx),我想匹配一些可以包含“.php”的路由。 我的nginx配置文件:Laravel:如何允许具有.php文件扩展名的路由,php,laravel,nginx,nginx-config,Php,Laravel,Nginx,Nginx Config,我正在使用homestead(所以我处理Nginx),我想匹配一些可以包含“.php”的路由。 我的nginx配置文件: server { listen 80; listen 443 ssl http2; server_name .homestead.test; root "/home/vagrant/code/test/public"; index index.html index.htm index.php; charset utf-8; location / { try_fi
server {
listen 80;
listen 443 ssl http2;
server_name .homestead.test;
root "/home/vagrant/code/test/public";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
add_header 0 false;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/homestead.test-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
ssl_certificate /etc/nginx/ssl/homestead.test.crt;
ssl_certificate_key /etc/nginx/ssl/homestead.test.key;
}
我想,我希望这与nginx设置有关。因为我遵循了这个解决方案,我几乎让它工作了,但不是我想要的方式(URL前面没有“配置”)您的配置包含以下内容:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
而且
请求URI,或者,如果URI以斜杠结尾,则请求URI附带由fastcgi_index指令配置的索引文件名。此变量可用于设置脚本文件名和路径转换参数,这些参数在PHP中确定脚本名称。例如,对于带有以下指令的“/info/”请求
这意味着,当请求URI包含.php
时,它被视为对php文件的请求,如果该php文件不存在,nginx将返回一个错误——它永远不会到达您的应用程序
解决方案是强制fastcgi\u script\u name
始终等于应用程序的入口点,在本例中为index.php
。您可以在位置块中编辑它,如下所示:
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
}
您的应用程序现在将接收每个请求,包括路径中包含.php
的请求