LNMP时,出现502 Bad Gateway的错误提示

      因为工作需要,要在ubuntu中安装LNMP环境,在这里,php是最新版本php7.1。一切都进展得很顺利,安装完成后,在浏览器中输入http://127.0.0.1/info.php,出现了502 Bad Gateway的错误提示。


打开/var/log/nginx 下的error.log,发现提示为:2017/07/15 14:46:47 [error] 1228#0: *8 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "127.0.0.1"。

进入/etc/php/7.1/fpm/pool.d下,打开www.conf文件,找到listen这一行,发现listen = /run/php/php7.1-fpm.sock。(我的php7.1-fpm.sock 在/var/run/php/php7.1-fpm.sock下,于是改成了/var/run/php/php7.1-fpm.sock)


进入/etc/nginx/sites-available目录下,打开default文件,里面的location配置为:

 location ~ \.php$ {
        #       fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
               fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
        #         fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        #         include fastcgi_params;
        #         fastcgi_index index.php;
         #       include fastcgi_params;
        #}


        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        }

很明显,default文件中的l监听方式和www.conf文件中的不一样,因此我改为:

 location ~ \.php$ {
        #       fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
                fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
                fastcgi_split_path_info ^(.+\.php)(/.*)$;
                include fastcgi_params;
                fastcgi_index index.php;
                include fastcgi_params;
        #}


        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        }


最终default文件如下:


保存这个配置后,重启Nginx ;service nginx restart,然后刷新浏览器,最后的结果展示如下:


问题得到了解决!

转载于:https://www.cnblogs.com/cmderq/p/9130835.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值