因为工作需要,要在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,然后刷新浏览器,最后的结果展示如下:

问题得到了解决!

LNMP时,出现502 Bad Gateway的错误提示的更多相关文章

  1. nginx显示静态html爆502 bad gateway的错误提示

    在centos的服务器上,没有启动php-fcgi. 本来是想设置显示一个静态文件目录的,用不着php,于是就关闭了php-fcgi. 结果打开爆了一个大大的nginx502 bad gateway的 ...

  2. Nginx 502/504 Gateway time-out错误完美解决方案【转发】

      在安装完Nginx+PHP-fpm+Mysql后,跑PHP的应用会经常出现504 Gateway Time-out 或者502 Bad Gateway的情况. Nginx 504 Gateway ...

  3. Nginx 502 Bad Gateway 的错误的解决方案

    我用的是nginx反向代理Apache,直接用Apache不会有任何问题,加上nginx就会有部分ajax请求502的错误,下面是我收集到的解决方案. 一.fastcgi缓冲区设置过小 出现错误,首先 ...

  4. nginx+php测试时显示 502 bad gateway的解决方法

    http://www.apelearn.com/study_v2/chapter18.html 由于阿铭老师的PHP版本是 5.3的   我装了 5.5 测试出现了 502  错误 查看日志   借助 ...

  5. JSP中,当页面为404或者500时。设置跳转到错误提示页面

    最好的就是在WEB.XML文件中配置错误代码的跳转页面,首先建立个 出现500错误的页面,提示出错了,然后再WEB.XML文件中配置,配置如下 一. 通过错误码来配置error-page <er ...

  6. Process启动.exe,当.exe内部抛出异常时,总会弹出一个错误提示框,阻止Process进入结束

    public class TaskProcess { [DllImport("kernel32.dll", SetLastError = true)] public static ...

  7. 在使用HTMLTestRunner时,报告为空,错误提示<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf_8'>

    <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf_8'> Time Elapsed: 0:00:21.3163 ...

  8. 记一次nginx部署yii2项目时502 bad gateway错误的排查

    周六闲来无事,就试着安装和部署下yii2,安装过程没什么问题,但部署到nginx上时遇到了502 bad gatewary问题,折腾了半天才搞定.这个问题是我以前在部署yii2时没有遇到过的,因此记在 ...

  9. LNMP环境出现”504 gateway time-out”错误的解决方案

    今天下午在调试测试VPS机器的时候,出现"504 gateway time-out"错误提示.VPS是安装的LNMP一键安装包,关于这个错误之前还没有见过,网上看到比较多的是502 ...

随机推荐

  1. SH2018笔试题之成长值问题

    一.题目 详见代码 二.代码 import java.util.Scanner; /** * 3 * 1 1 5 10 * 2 3 4 * 1 4 6 -5 */ public class main4 ...

  2. DOM事件第二弹(UIEvent事件)

    此文章主要总结UIEvent相关的事件,如有不对的地方,欢迎指正. 一.uitls.js(绑定事件公共类) var fixs = { 'focusin': { standard: 'focus', i ...

  3. Qt之自绘制饼图

    1.说明 最近在搞绘图方面的工作,说实话C++的第三方绘图库并不算多,总之我了解的有:qtcharts.ChartDirector.qwt.kdchart和QCustomPlot.这几个库各有利弊. ...

  4. asp.net core 系列 8 Razor框架路由(下)

    三.页面路由操作约定 接着上篇讲asp.net core 系列 7 Razor框架路由.在上篇继续第三节 "页面路由操作约定" 的最后一小节 AddPageRoute . 3.3. ...

  5. Chapter 5 Blood Type——21

    "Bella." Edward's voice was right beside me, relieved now. "Can you hear me?" “B ...

  6. C语言实现链栈的初始化&进栈&出栈&读取栈顶元素

    /*链表实现栈的一系列操作*/ #include<stdio.h> #include<stdlib.h> #define OK 1 #define ERROR 0 typede ...

  7. LeetCode数组解题模板

    一.模板以及题目分类 1.头尾指针向中间逼近 ; ; while (pos1<pos2) { //判断条件 //pos更改条件 if (nums[pos1]<nums[pos2]) pos ...

  8. 第9章 使用客户端凭据保护API - Identity Server 4 中文文档(v1.0.0)

    快速入门介绍了使用IdentityServer保护API的最基本方案. 我们将定义一个API和一个想要访问它的客户端. 客户端将通过提供ClientCredentials在IdentityServer ...

  9. .Net File类的操作

    //File类的常用操作方法 //File类的常用操作方法 //File.Exists //检测是否存在该文件 Exists //File.Create //创建一个文件 Create //File. ...

  10. .Net Core 实践 - 使用log4net记录日志(3)— log4net向ElasticSearch写日志

    demo地址:https://github.com/PuzzledAlien/log4net_demo/tree/master/DotNetCoreConsole_V3 Windows 10 安装部署 ...