zoukankan      html  css  js  c++  java
  • nginx 配置虚拟主机访问PHP文件 502错误的解决方法

    最近配置Nginx 服务器虚拟主机

    访问目录发现报502错误

    百度了很多方法 都不管用  我擦 各种抓狂-----

    原本Nginx配置如下:

    网上找了很多方法:

    查看日志   借助nginx的错误日志来进行排查vim /usr/local/nginx/logs/nginx_error.log 

    显示 : connect() to unix:/tmp/php-fcgi.sock failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /2.php HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-fcgi.sock:", host: "localhost"

    发现是fastcgi_pass路径的问题导致,

    借鉴以下解决方法

    解决方法一:

    # ll /tmp

    srw-rw---- 1 root  root     0 Feb 22 00:58 php-cgi.sock

    修改后的权限

    [root@centos  nginx]# chmod 777 /tmp/php-cgi.sock

    [root@centos nginx]# ll /tmp

    srwxrwxrwx 1 root  root     0 Feb 22 00:58 php-cgi.sock

    修改权限后测试成功

    重启  service php-fpm restart  

           service nginx restart 

    # ll /tmp

    srw-rw---- 1 root  root     0 Feb 22 00:58 php-cgi.sock

    权限又恢复了原样

    后修改  vim /etc/init.d/php-fpm    在start)  的fi  后加上 chmod 777 /tmp/php-cgi.sock

    解决方法二:   

    配置错误 因为 nginx 找不到php-fpm了,所以报错,一般是fastcgi_pass后面的路径配置错误了,后面可以是socket或者是ip:port

    修改php-fpm的配置文件  vim /usr/local/php/etc/php-fpm.conf   里面的 listen = /tmp/php-fcgi.sock  改为  listen = 127.0.0.1:9000

    修改nginx的配置文件   vim /usr/local/nginx/conf/nginx.conf     里面的 fastcgi_pass unix:/tmp/php-cgi.sock; 改为 fastcgi_pass 127.0.0.1:9000;

    就此  访问解析成功

  • 相关阅读:
    Python staticmethod() 函数
    Python open() 函数
    Python input() 函数
    Python divmod() 函数
    Python abs() 函数
    instanceof和类型转换
    多态
    方法重写
    this
    Super详解
  • 原文地址:https://www.cnblogs.com/bcphp/p/7428275.html
Copyright © 2011-2022 走看看