我正在努力解决 LEMP 堆栈上的 NGINX 配置问题。在 PHP 中,$_SERVER['REQUEST_METHOD']
即使请求方法是 POST,其值也始终为 GET。
跑步:
- Ubuntu 18.04
- PHP 版本 7.2.24-0ubuntu0.18.04.6
- nginx/1.14.0
这是服务器配置:
server {
server_name my-site.com;
root /var/www/my-site.com/html/;
index index.php index.html;
location ~* \.php$ {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
location / {
try_files $uri $uri/ /api/index.php?$query_string;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/my-site.com-0001/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/my-site.com-0001/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = my-site.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name my-site.com;
listen 80;
return 404; # managed by Certbot
}
我对此进行了一些阅读,并检查以确保这/etc/nginx/fastcgi_params
是 Ubuntu/NGINX 默认设置:
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
有人知道如何解决这个问题吗?
答案1
按照上面评论中的@richardsmith的说法,HTTPS 到 HTTP 的重定向导致方法从 POST 更改为 GET。