Home Backend Development PHP Tutorial 将PHP从5.3.28升级到5.3.29时Nginx出现502错误_php技巧

将PHP从5.3.28升级到5.3.29时Nginx出现502错误_php技巧

May 16, 2016 pm 08:16 PM
502 error nginx

今天将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
重启服务,问题解决。

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 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 configure cloud server domain name in nginx How to configure cloud server domain name in nginx Apr 14, 2025 pm 12:18 PM

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.

How to check whether nginx is started How to check whether nginx is started Apr 14, 2025 pm 01:03 PM

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.

How to create a mirror in docker How to create a mirror in docker Apr 15, 2025 am 11:27 AM

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.

How to check nginx version How to check nginx version Apr 14, 2025 am 11:57 AM

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 start nginx server How to start nginx server Apr 14, 2025 pm 12:27 PM

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

How to check whether nginx is started? How to check whether nginx is started? Apr 14, 2025 pm 12:48 PM

In Linux, use the following command to check whether Nginx is started: systemctl status nginx judges based on the command output: If "Active: active (running)" is displayed, Nginx is started. If "Active: inactive (dead)" is displayed, Nginx is stopped.

How to start nginx in Linux How to start nginx in Linux Apr 14, 2025 pm 12:51 PM

Steps to start Nginx in Linux: Check whether Nginx is installed. Use systemctl start nginx to start the Nginx service. Use systemctl enable nginx to enable automatic startup of Nginx at system startup. Use systemctl status nginx to verify that the startup is successful. Visit http://localhost in a web browser to view the default welcome page.

How to solve nginx403 How to solve nginx403 Apr 14, 2025 am 10:33 AM

How to fix Nginx 403 Forbidden error? Check file or directory permissions; 2. Check .htaccess file; 3. Check Nginx configuration file; 4. Restart Nginx. Other possible causes include firewall rules, SELinux settings, or application issues.

See all articles