php - nginx try_files php file is not parsed
问题描述
My project was split into three projects for historical reasons
This makes the nginx configuration file exceptionally difficult to handle, so much that I have tried many solutions and still haven't solved it perfectly.
Directory configuration:
- /var/www/html/: project directory
- /mnt/a.com/: another project directory
- The third project uses a reverse proxy
The configuration file is as follows:
server {
listen 80;
listen [::]:80 default ipv6only=on;
server_name _;
root /var/www/html;
index index.html index.htm index.php;
sendfile off;
location / {
try_files $uri $uri/index.html $uri/index.htm $uri/index.php @mnt;
# try_files $uri $uri/ @mnt;
# This annotated code causes a 403 error to be returned when accessing an empty directory instead of redirecting to @mnt
}
location @mnt {
root /mnt/a.com;
try_files $uri $uri/index.html $uri/index.htm $uri/index.php @proxy;
}
location @proxy {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://a-proxy.com;
}
location ~ \.php$ {
try_files $uri @mntphp;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
location @mntphp {
root /mnt/a.com;
try_files $uri @proxy;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
# deny access to . files, for security
location ~ /\. {
log_not_found off;
deny all;
}
location ~* \.(jpg|jpeg|gif|png|css|js|ico|webp|tiff|ttf|svg)$ {
expires 2d;
}
error_log /var/log/a.com_error.log;
access_log /var/log/a.com.log;
}
But such a configuration will cause the php file to fail to parse. I know this is because try_files will redirect only the last parameter, but I don't know how to solve this
解决方案
推荐阅读
- spring-boot - MapStruct 映射器返回空映射对象
- android - 系统/应用程序中的 APK 何时安装?
- react-admin - react-admin v 3.9.6 的多个数据提供者
- javascript - jQuery 替换文本但不去除 HTML
- scala - 关于 option.contains() 的 Scala 问题
- angular - 为什么我不能以角度保存我的获取请求?
- python - 如何使用 Keras 进行多类分类?
- sql-server - SSMS 特定页面以及如何到达那里
- azure - Azure 数据工厂计划触发器不同的环境设置
- ios - Firebase - 删除 1 个节点的密钥会影响另一个节点的相同密钥