Table of Contents
关于NGINX的502的装逼打怪之路,nginx502之路
Home php教程 php手册 关于NGINX的502的装逼打怪之路,nginx502之路

关于NGINX的502的装逼打怪之路,nginx502之路

Jun 13, 2016 am 08:56 AM
nginx about of

关于NGINX的502的装逼打怪之路,nginx502之路

写日志之前先copy一段nginx502的原因,从某网看到如下,然而这并不是重点,最重要还是看博主手敲的东西。

一、NGINX 502错误排查
NGINX 502 Bad Gateway错误是FastCGI有问题,造成NGINX 502错误的可能性比较多。将网上找到的一些和502 Bad Gateway错误有关的问题和排查方法列一下,先从FastCGI配置入手:
1.FastCGI进程是否已经启动
2.FastCGI worker进程数是否不够
运行 netstat -anpo | grep “php-cgi” | wc -l 判断是否接近FastCGI进程,接近配置文件中设置的数值,表明worker进程数设置太少
3.FastCGI执行时间过长
根据实际情况调高以下参数值
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
4.FastCGI Buffer不够
nginx和apache一样,有前端缓冲限制,可以调整缓冲参数
fastcgi_buffer_size 32k;
fastcgi_buffers 8 32k;
5.Proxy Buffer不够
如果你用了Proxying,调整
proxy_buffer_size   16k;
proxy_buffers    4 16k;
参见:http://www.server110.com
6.https转发配置错误
正确的配置方法
server_name www.mydomain.com;
location /myproj/repos {
set $fixed_destination $http_destination;
if ( $http_destination ~* ^https(.*)$ )
{
set $fixed_destination http$1;
}
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Destination $fixed_destination;
proxy_pass http://subversion_hosts;
}
当然,还要看你后端用的是哪种类型的FastCGI,我用过的有php-fpm,流量约为单台机器40万PV(动态页面), 现在基本上没有碰到502。

7.php脚本执行时间过长
将php-fpm.conf的0s的0s改成一个时间

 

 ~~~~~~~~~~~~~~~~~~~~~~~~~~~华丽丽的分割线~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

博主遇到的问题是因为代码中有一个参数通过引用传递,然后访问之后直接502,博主看到此信息,第一时间是直接把display_errors打开,

然后我就有疑问了为什么打开了错误显示,就不502了,只是有些E_STRICT的警告,之后经过了一轮轮调试,仍旧没有办法之后原因。

无可奈何之后查看了nginx的错误截图如下。当时想这尼玛不是php fastcgi的报错,为什么会出现在nginx的错误日志里面,这感觉不怎么科学,苦思冥想

再经过几轮伤痛无果的调试,依然感觉无力,只能先暂告一段落。

作为一个幸运的程序员,不知道动了那根筋想倒腾一下之后本地虚拟机环境中一直不写错误日志文件的问题,配置是没有问题,就是不写错误日志。(各位看官不要吐槽,因为博主平常都是 直接页面显示错误加xdebug,所以觉得无所谓,不写关我毛毛雨的事情,不虚。)博主慧眼加高等智慧的大脑(这个时代写博主必须加点逼格)觉得应该是文件权限的问题,然后果断来一下 chmod 777高超技能,重启php-fpm,来段错误代码测试了一下,尼玛还是如预期写入了错误日志文件。此刻回想起来上午的问题,总感觉输出的错误警告神马会不会和写入日志的一样。觉 得那就裸衣干,tail一下错误日志,屏蔽display,撸一下代码,尼玛此刻竟然不报502了,完美运行,错误日志如期写入日志文件,不科学啊,打开nginx的错误日志再撸一发发现nginx没有了 错误。 好吧!感觉问题找到了关于502错误是因为php的错误日志权限问题,没有办法写入,然后直接抛给了cgi,所以nginx就502了。至于为什么会下抛给cgi,这个我也不懂,别问我,懂的人后面 过几招。 哎呦,不错哦。此段装逼路程结束。谢谢Tvb,谢谢爸妈,谢谢博客园。  
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to allow external network access to tomcat server How to allow external network access to tomcat server Apr 21, 2024 am 07:22 AM

To allow the Tomcat server to access the external network, you need to: modify the Tomcat configuration file to allow external connections. Add a firewall rule to allow access to the Tomcat server port. Create a DNS record pointing the domain name to the Tomcat server public IP. Optional: Use a reverse proxy to improve security and performance. Optional: Set up HTTPS for increased security.

What are the nginx start and stop commands? What are the nginx start and stop commands? Apr 02, 2024 pm 08:45 PM

The start and stop commands of Nginx are nginx and nginx -s quit respectively. The start command starts the server directly, while the stop command gracefully shuts down the server, allowing all current requests to be processed. Other available stop signals include stop and reload.

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

How to register phpmyadmin How to register phpmyadmin Apr 07, 2024 pm 02:45 PM

To register for phpMyAdmin, you need to first create a MySQL user and grant permissions to it, then download, install and configure phpMyAdmin, and finally log in to phpMyAdmin to manage the database.

How to deploy nodejs project to server How to deploy nodejs project to server Apr 21, 2024 am 04:40 AM

Server deployment steps for a Node.js project: Prepare the deployment environment: obtain server access, install Node.js, set up a Git repository. Build the application: Use npm run build to generate deployable code and dependencies. Upload code to the server: via Git or File Transfer Protocol. Install dependencies: SSH into the server and use npm install to install application dependencies. Start the application: Use a command such as node index.js to start the application, or use a process manager such as pm2. Configure a reverse proxy (optional): Use a reverse proxy such as Nginx or Apache to route traffic to your application

Welcome to nginx!How to solve it? Welcome to nginx!How to solve it? Apr 17, 2024 am 05:12 AM

To solve the "Welcome to nginx!" error, you need to check the virtual host configuration, enable the virtual host, reload Nginx, if the virtual host configuration file cannot be found, create a default page and reload Nginx, then the error message will disappear and the website will be normal show.

How to solve the problem of nginx when accessing the website How to solve the problem of nginx when accessing the website Apr 02, 2024 pm 08:39 PM

nginx appears when accessing a website. The reasons may be: server maintenance, busy server, browser cache, DNS issues, firewall blocking, website misconfiguration, network connection issues, or the website is down. Try the following solutions: wait for maintenance to end, visit during off-peak hours, clear your browser cache, flush your DNS cache, disable firewall or antivirus software, contact the site administrator, check your network connection, or use a search engine or web archive to find another copy of the site. If the problem persists, please contact the site administrator.

How to communicate between docker containers How to communicate between docker containers Apr 07, 2024 pm 06:24 PM

There are five methods for container communication in the Docker environment: shared network, Docker Compose, network proxy, shared volume, and message queue. Depending on your isolation and security needs, choose the most appropriate communication method, such as leveraging Docker Compose to simplify connections or using a network proxy to increase isolation.

See all articles