ubuntu nginx+php环境520错误

  前两天新装了一个系统ubuntu 14.04,以前都是用linux mint 和 centos kde ;装了一个nginx+php5-fpm环境,一直调试失败。问题出现 502 bad gateway 系统环境问题

看了一下nginx 输出的error.log文件出现:

connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"

nginx 配置文件都修改了还是不行。

location ~ \\.php$ {
root /www/test;#此处和server下面root保持一致,默认为html
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/test/$fastcgi_script_name;
include fastcgi_params;
}

这个解析php配置是真确的,找了很多原因才找到,我在/var/run/没有找到php5-fpm.sock,证明是php启动失败或者配置问题,随后我用sudo php5-fpm -t 提示:

[28-May-2015 21:17:21] ALERT: 
[28-May-2015 21:17:21] ERROR: failed to post process the configuration
[28-May-2015 21:17:21] ERROR: FPM initialization failed

查明原来是php5-fpm 配置问题,随后我看了一下,需要规则去配置大小:


pm.max_children = 20
pm.start_servers = 2
pm.min_spare_servers = 100
pm.max_spare_servers = 60
pm.max_requests = 1000

规则如下:min_spare_servers ≤ start_servers ≤ max_spare_servers ≤ max_children 

我的更改如下:


pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 2
pm.max_requests = 500 

保存后,我再使用php5-fpm -t,出现

[28-May-2015 21:19:47] NOTICE: configuration file /etc/php5/fpm/php-fpm.conf test is successful

配置是正确成功,重启一起php和nginx,再到/var/run/找到php5-fpm.sock,页面正常显示和解析。

 

观点:凡是系统出现问题,自己要先静下心来思考和排查问题的根本,不懂就要根据问题提示去google和百度。

posted @ 2015-05-28 21:51  Hande.xu  阅读(756)  评论(0)    收藏  举报