关于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

AI Hentai Generator
Generate AI Hentai for free.

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

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.

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.

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.

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.

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

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.

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.

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.
