昨天接到一個網友的問題,說yum安裝nginx+php-fpm+mysql+phpMyAdmin后,發明phpMyAdmin無法打開,一直報502錯誤已經抓狂半天了,本著輔佐別人快樂本身的原則,長途幫他看了一下, 現記錄和總結如下,問題辦理思路的總結放在文章最后,問題辦理思路總結也是本文的重點。
問題情況:CentOS6通過yum安裝的nginx+php-fpm+mysql+phpMyAdmin
問題描寫:安裝完成后發明nginx沒有問題,而phpMyAdmin無法打開,提示502錯誤
問題辦理進程
查察問題情況的安裝包:
nginx-filesystem-1.0.15-12.el6.noarch |
nginx-1.0.15-12.el6.x86_64 |
rrdtool-php-1.3.8-7.el6.x86_64 |
php-pear-1.9.4-4.el6.noarch |
php-devel-5.3.3-46.el6_6.x86_64 |
php-mbstring-5.3.3-46.el6_6.x86_64 |
php-mcrypt-5.3.3-3.el6.x86_64 |
php-5.3.3-46.el6_6.x86_64 |
php-tidy-5.3.3-46.el6_6.x86_64 |
php-pecl-memcache-3.0.5-4.el6.x86_64 |
php-xmlrpc-5.3.3-46.el6_6.x86_64 |
php-xmlseclibs-1.3.1-3.el6.noarch |
php-common-5.3.3-46.el6_6.x86_64 |
php-pdo-5.3.3-46.el6_6.x86_64 |
php-xml-5.3.3-46.el6_6.x86_64 |
php-fpm-5.3.3-46.el6_6.x86_64 |
php-cli-5.3.3-46.el6_6.x86_64 |
php-mysql-5.3.3-46.el6_6.x86_64 |
php-eaccelerator-0.9.6.1-1.el6.x86_64 |
php-gd-5.3.3-46.el6_6.x86_64 |
按照nginx報的502錯誤,可以劈頭判定是upstream呈現了問題,再提到upstream之前,先列一下nginx的設置文件(去掉注釋,我已經將nginx記錄錯誤日志的級別從默認級別晉升到info)。
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
client_max_body_size 10M;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}
由于此設置文件中沒有顯式寫明任何server,因此需要查察一下include /etc/nginx/conf.d/*.conf; 所包括的默認server文件,即/etc/nginx/conf.d/default.conf,去掉注釋
cat /etc/nginx/conf.d/default.conf
server {
listen 80 default_server;
server_name _;
include /etc/nginx/default.d/*.conf;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ [^/].php(/|$) {
fastcgi_split_path_info ^(.+?.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
劈頭判定,此nginx的設置確實沒有問題,應該是php-fpm可能php自己的問題(縮小問題范疇)。
查閱nginx日志文件(/var/log/nginx/error.log),發明如下提示,確定是php-fpm的問題,fastcgi也算是對upstream的一種署理