Nginx 之常见报错问题解决
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx 之常见报错问题解决相关的知识,希望对你有一定的参考价值。
楼主在配置完成后,是可以访问的。但是后把 listen = 127.0.0.1:9000 改成 listen = /tmp/dis.sock,造成以上 502 的报错,nginx.conf 的配置 是fastcgi_pass 127.0.0.1:9000;
。如果php-fpm 要更改为listen = /tmp/dis.sock,那么nginx.conf 也要改为 fastcgi_pass unix:/tmp/dis.sock;即两边的监听方式要一样。
[[email protected] ~]# vim /usr/local/php/etc/php-fpm.conf #查看php-fpm.conf 的配置文件
#这样的配置楼主访问访坛就会报 502 的错
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[dis]
listen = /tmp/dis.sock
#listen = 127.0.0.1:9000
user = php-fpm
group = php-fpm
listen.owner = nobody #监听的对象
listen.group = nobody #组
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
--------------------------------------------------
[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf #nginx 的配
user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 6000;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip ‘$remote_addr $http_x_forwarded_for [$time_local]‘
‘$host "$request_uri" $status‘
‘"$http_referer" "$http_user_agent"‘;
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm application/xml;
server
{
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /usr/local/nginx/html;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/dis.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
}
}
}
楼主把上述的配置改为一样的监听方式后还是 报502 不能访问。于是查看ngnix 的日志
发现 /tmp/dis.sock 没有访问权根
[[email protected] ~]# cat /usr/local/nginx/logs/nginx_error.log
[[email protected] etc]# ls -l /tmp/dis.sock #属主 属组都是可以访问的,但是其他用户没有读的权限
srw-rw---- 1 root root 0 Nov 25 07:08 /tmp/dis.sock
[[email protected] ~]# ps aux |grep nginx #要读sock 是nginx 的nobody .
root 1665 0.0 0.0 20460 668 ? Ss 07:08 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody 1666 0.0 0.3 23168 4012 ? S 07:08 0:00 nginx: worker process
nobody 1667 0.0 0.3 23156 4008 ? S 07:08 0:00 nginx: worker process
root 2016 0.0 0.0 103260 832 pts/0 S+ 08:10 0:00 grep nginx
nginx 中读 sock 是 nobody 用户,那么我们就要给他权限
在php-fpm 的配置中加入
listen.owner = nobody #监听的用户
listen.group = nobody #组的人
[[email protected] ~]# /etc/init.d/php-fpm restart # 重启php-fpm
再刷新论坛,是可以正常访问的。
有图有真相;
本文出自 “CBO#Boy_Linux之路” 博客,请务必保留此出处http://20151213start.blog.51cto.com/9472657/1876422
以上是关于Nginx 之常见报错问题解决的主要内容,如果未能解决你的问题,请参考以下文章