关于NGINX的502的装逼打怪之路,nginx502之路
关于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的
~~~~~~~~~~~~~~~~~~~~~~~~~~~华丽丽的分割线~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
博主遇到的问题是因为代码中有一个参数通过引用传递,然后访问之后直接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,谢谢爸妈,谢谢博客园。
Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

When the Nginx server goes down, you can perform the following troubleshooting steps: Check that the nginx process is running. View the error log for error messages. Check the syntax of nginx configuration. Make sure nginx has the permissions you need to access the file. Check file descriptor to open limits. Confirm that nginx is listening on the correct port. Add firewall rules to allow nginx traffic. Check reverse proxy settings, including backend server availability. For further assistance, please contact technical support.
