将PHP从5.3.28升级到5.3.29时Nginx出现502错误,5.3.29nginx
将PHP从5.3.28升级到5.3.29时Nginx出现502错误,5.3.29nginx
今天将PHP从5.3.28升级到5.3.29,发现网站打不开了,提示”502 bad gateway”,访问静态资源可以,但访问任何PHP文件都会502。
其实之前也发现这个问题,只是一直没找到解决办法,所以我一直将PHP保持在5.3.28版本。
按照我以前的脾气,我什么软件都得要最新的稳定版,但PHP之类的软件是例外,因为版本高了,会导致很多程序不兼容,相对来说5.3兼容性算是最好的版本之一,当然5.2也可以。
强迫症实在受不了,官方说5.3.29是5.3的最后一个版本,最后一个版本出现这种问题又一直没解决让我很难受。
网上搜索了一下,没人出现我这种问题,所有的编译过程,配置过程,都是照旧,之前从5.3.25一直到5.3.28都是用的我写的同一个升级脚本,按道理同一个子版本系列,一样的编译和配置过程,不应该出现问题的。
为何5.3.25一直到5.3.28都没问题,到了5.3.29就没问题了呢?
今天终于把问题的根源找到了,我也是醉了……
由于我不想占用额外的端口,所以Nginx和PHP-FPM之间一直使用的Unix socket,而且据说这种方式效率也高一些。
PHP升级到5.3.29以后,出现502错误,而且是一打开网页就报错了,不像是由于PHP执行超时导致的Nginx提示502,更像是PHP-FPM异常终止了,或者是Ngxin根本没有连接上fastcgi。
使用PHP-FPM的日志也是郁闷,我明明开启了日志,还设置了日志路径,但还是没有生成日志。
好吧,根据前面的思路推测出来的原因找问题:
1.PHP-FPM一开始工作就异常终止了;
2.Ngxin根本没有连接上fastcgi。
第一种可能直接就排除了,因为出现502错误的时候,后台的PHP-FPM进程并没有退出,还存活得好好的。
那么很可能是第二种可能了,我把Nginx和PHP-FPM的配置文件修改了一下,改成了传统的“地址:端口”的形式
PHP-FPM配置文件中:
listen = 127.0.0.1:1234
Nginx配置文件中:
fastcgi_pass 127.0.0.1:1234
重启服务,网站竟然顺利打开了。
看来就是Nginx没有连接上PHP-FPM了,那么问题出在哪里呢?难道5.3.29去掉了Unix socket的连接方式?我觉得不大可能,查阅更新日志,也没有看到有关的项目啊。
我将Nginx和PHP-FPM的配置文件改回去。
PHP-FPM配置文件中:
listen = /tmp/php-cgi.sock
Nginx配置文件中:
fastcgi_pass unix:/tmp/php-cgi.sock;
重启服务,立马又502了。
首先想到了检查权限,反正是测试,所以我二话不说直接把那个PHP-FPM的sock文件权限改为777。
chmod 777 /tmp/php-cgi.sock
直接打开网页,能打开!
好吧,就是权限问题了,重启服务,查看php-cgi.sock 的权限
-rwx------. 1 root root 663 9月 18 00:16 php-cgi.sock
这。。。原因已经很明了了,怪不得Nginx连不上PHP-FPM,php-cgi.sock的权限竟然是700,
但问题来了,为什么同样的编译和配置过程,5.3.28之前的版本就没问题呢?我查看另一台没有升级5.3.29的服务器:
srw-rw-rw- 1 root root 0 9月 16 21:11 php-cgi.sock
发现其权限是666,这……无法理解了……为什么5.3.28的默认权限配置是666,到了5.3.29就变成700了呢?
查阅PHP文档,找到解决办法
将PHP-FPM里的配置文件加入,前两项是指定php-cgi.sock的拥有者和用户组,后一项是指定文件权限。
listen.owner = www
listen.group = www
listen.mode = 0666
重启服务,问题解决。

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 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.

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 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.

Steps to create a Docker image: Write a Dockerfile that contains the build instructions. Build the image in the terminal, using the docker build command. Tag the image and assign names and tags using the docker tag command.

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

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).

To get Nginx to run Apache, you need to: 1. Install Nginx and Apache; 2. Configure the Nginx agent; 3. Start Nginx and Apache; 4. Test the configuration to ensure that you can see Apache content after accessing the domain name. In addition, you need to pay attention to other matters such as port number matching, virtual host configuration, and SSL/TLS settings.

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".
