今天我将本地服务器从 nginx 1.6.3 升级到 1.8.0,现在我所有的本地网站都502错误的网关。
一个标准的 nginx 配置文件如下
server {
charset utf-8;
client_max_body_size 128M;
listen 80; ## listen for ipv4
server_name yii2.dive;
root /media/Development/www/yii2/web;
index index.php;
access_log /media/Development/www/yii2/log/access.log combined;
error_log /media/Development/www/yii2/log/error.log warn;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi.conf;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
try_files $uri =404;
}
location ~ /\.(ht|svn|git) {
deny all;
}
}
我收到的错误消息如下
2015/05/12 14:09:21 [error] 9295#0: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: yii2.dive, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "yii2.dive"
/var/run/php5-fpm.sock 处的套接字存在,因此那里没有问题。
我发现其他人在同一个升级中遇到了问题但他们的问题与我的不同,并且没有任何错误。
我尝试将这一行添加到/etc/nginx/fastcgi_params但这并不能缓解问题。
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
或者有没有办法降级回 1.6.2 或 1.6.3,这样我以后就可以处理这个升级了。我尝试运行
sudo apt-get install nginx=1.6.2-1+trusty0
但出现以下错误
The following packages have unmet dependencies:
nginx : Depends: nginx-full (< 1.6.2-1+trusty0.1~) but 1.8.0-1+trusty1 is to be installed or
nginx-light (< 1.6.2-1+trusty0.1~) but it is not going to be installed or
nginx-extras (< 1.6.2-1+trusty0.1~) but it is not going to be installed or
nginx-naxsi (< 1.6.2-1+trusty0.1~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
答案1
这对我有用
代替
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
和
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
答案2
使用以下命令删除所有 nginx 数据包:
aptitude purge nginx nginx-full
然后添加官方 nginx deb repos:
deb http://nginx.org/packages/debian/ codename nginx
deb-src http://nginx.org/packages/debian/ codename nginx
wget http://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key
最后安装nginx:
apt-get update
apt-get install nginx
https://nginx.org/en/linux_packages.html
现在应该可以正常工作了。如果不行,请查看/var/log/nginx/error.log
并修复错误。