LNMP里常见的502问题
講關于nginx的高級配置,在Apache講了很多關于“用戶認證”、“日志”、“重定向”等等操作,當然nginx也會有相同的操作。
首先,我們把Discuz在Nginx下實現訪問,用之前的域名www.test.com
進入目錄
[root@LampLinux vhosts]# cd /usr/local/nginx/conf/vhosts/
創建test.conf文件
[root@LampLinux vhosts]# vim test.conf
寫入如下代碼(紅色部分為變更后的信息)
server
{
? ? listen 80;
? ? server_name www.test.com;
? ? index index.html index.htm index.php;
? ? root /data/www;
? ? location ~ \.php$ {
? ? ? ? include fastcgi_params;
? ? ? ? fastcgi_pass unix:/tmp/www.sock;
? ? ? ? fastcgi_index index.php;
? ? ? ? fastcgi_param SCRIPT_FILENAME ?/data/www$fastcgi_script_name;
? ? }
}
重啟Nginx
[root@LampLinux vhosts]# /usr/local/nginx/sbin/nginx -t
[root@LampLinux vhosts]# /etc/init.d/nginx reload
瀏覽器輸入:www.test.com,顯示502錯誤。
我們該怎么樣排查502錯誤呢?
首先,我們先排查Nginx的錯誤日志:
進入nginx配置文件:
[root@LampLinux vhosts]# vim /usr/local/nginx/conf/nginx.conf
找到如下信息:?
error_log /usr/local/nginx/logs/nginx_error.log crit;
可以看出紅字部分為“錯誤日志”的路徑和文件。
查看文件內容:
[root@LampLinux vhosts]# cat /usr/local/nginx/logs/nginx_error.log
有很多內容,但是有一行Unix:/tmp/www.sock?failed (13:permission denied),表示沒有權限去讀取文件。
我們來查看/tmp/www.sock文件的權限:
[root@LampLinux vhosts]# ls -l /tmp/www.sock
?srw-rw----. 1 root ?root ?0 8月 ?12 01:19 /tmp/www.sock
那么讀這個.sock文件的用戶是誰?
[root@LampLinux vhosts]# ps aux |grep nginx
root ? ? 10929 ?0.0 ?0.1 ? 5516 ?1448 ? ? ? ? ?Ss ? 00:59 ? 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody ? 11039 ?0.0 ?0.2 ? 7112 ?2880 ? ? ? ? ?S ? ?01:16 ? 0:00 nginx: worker process
nobody ? 11040 ?0.0 ?0.2 ? 6768 ?2272 ? ? ? ? ?S ? ?01:16 ? 0:01 nginx: worker process
root ? ? 11115 ?0.0 ?0.0 ? 5980 ? 756 pts/0 ? ?S+ ? 03:06 ? 0:00 grep nginx
我們可以看出,用戶是nobody,這一點很重要;
為什么是nobody呢?
我們在配置文件的時候指定了Unix:/tmp/www.sock,讓它去那里讀取,由于沒有權限,所以它會顯示502錯誤。
怎么讓.sock可讀?
編輯php-fpm的配置文件:
[root@LampLinux vhosts]# vim /usr/local/php2/etc/php-fpm.conf
在php-fpm配置中的:
user = php-fpm
group = php-fpm?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 下面寫入配置(關于指定監聽用戶和組的人是誰?)
listen.owner = nobody
listen.group = nobody
保存退出
:wq
重啟php-fpm服務
[root@LampLinux vhosts]# /usr/local/php2/sbin/php-fpm -t
[root@LampLinux vhosts]# /etc/init.d/php-fpm restart
瀏覽器輸入www.test.com? 就沒有問題了,502的問題解決了。
轉載于:https://blog.51cto.com/286577399/1683779
總結
以上是生活随笔為你收集整理的LNMP里常见的502问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 做梦梦到抓了好多大鱼
- 下一篇: 为什么会一直梦到前任