最近发现,wordpress 4.7 在登录后,如果再次访问自己站点会直接出现502错误,但是如果非登录状态,则访问都是正常的。这个现象非常奇怪。无论如何,先登录服务器看日志:
tail -f /var/log/nginx/error.log
然后在登录状态下访问我的网站,发现有如下日志,
2016/12/21 14:59:57 [error] 8551#0: *26 upstream sent too big header while reading response header from upstream, client: **.*.*.*, server: idocbox.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "idocbox.com", referrer: "http://idocbox.com/wp-admin/plugins.php?plugin_status=all&paged=1&s"
看来是头信息过大导致超时了,所以出现了502错误。一番简单搜索,得到如下解决方案:
sudo vi /etc/nginx/sites-enabled/idocbox.com
在里面增加
fastcgi_buffer_size 128k; fastcgi_buffers 32 32k;
修改后配置片段,
location ~ \.php$ { fastcgi_buffer_size 128k; fastcgi_buffers 32 32k; fastcgi_split_path_info ^(.+\.php)(/.+)$; # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # # # With php5-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; }
然后重启nginx,
sudo service nginx restart
验证:再次在登录状态下访问网站,网站正常了,日志里面也没有了那个“upstream sent too big” 错误。