我已经使用NGINX和PHP-FPM设置了一些站点。 我的PHP网站上有一个名为“ / auth / signin”的URL,到目前为止,在使用GET请求时,该URL都可以正常工作。单击此页面上的登录后,使用POST调用相同的路径,并以“找不到404文件”结尾。
如果我将try_files $uri $uri/ /index.php?$args =404;
直接放到服务器块中,则一切正常,因此我猜POST请求没有被location /
捕获。
我无法向我解释这种行为,希望有人能够这样做。
这是我的NGINX站点配置:
server {
listen 80;
listen 443 ssl;
listen [::]:443 ssl;
include conf.d/ssl-params.conf;
server_name www.example.com example.com;
root /var/www/html;
index index.php index.html;
# Block unwanted request methods
if ($request_method !~ ^(GET|HEAD|POST|PUT|DELETE)$ ) {
return 405;
}
# Block bad bots
if ($http_user_agent ~* "agent1|Wget|Catall Spider" ) {
return 403;
}
set $skip_cache 0;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $skip_cache 1;
}
if ($query_string != "") {
set $skip_cache 1;
}
location / {
ModSecurityEnabled on;
ModSecurityConfig /etc/nginx/modsec/main.conf;
try_files $uri $uri/ /index.php?$args;
}
location ~ /\.ht {
deny all;
}
location /redis-fetch {
internal ;
set $redis_key $args;
redis_pass redis:6379;
}
location /redis-store {
internal ;
set_unescape_uri $key $arg_key ;
redis2_query set $key $echo_request_body;
redis2_query expire $key 14400;
redis2_pass redis:6379;
}
location ~ \.php$ {
set $key "nginx-cache:$scheme$request_method$host$request_uri";
try_files $uri $uri/ /index.php?$args =404;
srcache_fetch_skip $skip_cache;
srcache_store_skip $skip_cache;
srcache_response_cache_control off;
set_escape_uri $escaped_key $key;
srcache_fetch GET /redis-fetch $key;
srcache_store PUT /redis-store key=$escaped_key;
more_set_headers 'X-Cache $srcache_fetch_status';
more_set_headers 'X-Cache-2 $srcache_store_status';
fastcgi_pass php-fpm:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
fastcgi_keep_conn on;
include fastcgi_params;
}
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off;
log_not_found off;
expires max;
}
location = /robots.txt {
access_log off;
log_not_found off;
}
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
}
Iv还通过始终使用不同的查询字符串进行测试来确保不会缓存这些内容。
谢谢! 友好的问候 尼科