我有一个使用 Ubuntu 20.04、php 8.1 和 nginx 1.23.1 的网站。如果我重新启动 nginx 和 php-fpm,我可以登录、浏览网站,一切正常。如果我等待一段时间而网站上没有任何活动(10-15 分钟?),无论我尝试访问哪个页面,我都会开始收到 302 Found 错误。如果我再次重新启动 nginx 和 php-fpm,一切都会重新开始工作。我不知道是什么原因造成的。这是网站的 nginx 配置文件:
server {
listen 1443 ssl;
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains" ;
server_name my_site;
root /var/www/my_site/htdocs;
index index.php index.html;
access_log /var/log/nginx/my_site.access.log;
error_log /var/log/nginx/my_site.error.log;
ssl_certificate /etc/nginx/ssl/all.my_site.com.crt;
ssl_certificate_key /etc/nginx/ssl/all.my_site.com.key;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK';
ssl_prefer_server_ciphers on;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
location / {
try_files $uri =404;
# pass PHP scripts to FastCGI server
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param ALL_FILES_PATH /var/www/my_site;
fastcgi_param LOCAL_FILES_PATH /var/www/my_site;
fastcgi_param SHARED_FILES_PATH /var/www/my_site-web-8.1;
fastcgi_read_timeout 604800;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
}
编辑:看来这个 302 错误只发生在 PHP 文件中。我放入了一个基本的 html 文件,它加载时返回 200 响应代码。