nginx的文件提示502就是服务没有启动,这里不管是php还是java。出现502的问题都是服务没有启动,下面浮现一下,首先在nginx的配置文件里写了一个php版本的文件。
[root@wulaoer ~]# cat /home/wwwroot/default/index.php 
<?php
    // 顺便可以看一下php的扩展全不全
    phpinfo();
然后配置一下nginx配置,直接请求index.php文件。
server
    {
        listen 80 default_server reuseport;
        #listen [::]:80 default_server ipv6only=on;
        server_name _;
        index index.html index.htm index.php;
        root  /home/wwwroot/default;
        #error_page   404   /404.html;
        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
        include enable-php.conf;
        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }
        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }
        location ~ /.well-known {
            allow all;
        }
        location ~ /\.
        {
            deny all;
        }
        access_log  /home/wwwlogs/access.log;
    }
为了测试nginx的默认配置是否影响php文件,我重新开一个端口,并安装php文件,可以参考:https://www.wulaoer.org/?p=1454
[root@wulaoer ~]# cat /usr/local/nginx/conf/vhost/8011.conf 
server { 
    listen       8011; 
    server_name  test.cn; 
    location ~ \.php?.*$ { 
        root           /home/wwwroot/default; 
        fastcgi_pass   127.0.0.1:9000; 
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
        include        fastcgi_params; 
    } 
}
已经配置好了,下面没有启动php进行一下验证
[root@wulaoer ~]# curl http://10.211.55.5:8011/index.php <html> <head><title>502 Bad Gateway</title></head> <body> <center><h1>502 Bad Gateway</h1></center> <hr><center>nginx</center> </body> </html>
启动php后如果还是提示502,需要配置一下/etc/selinux/config把SELINUX的参数改为SELINUX=disabled即可,下面测试一下
[root@wulaoer ~]# systemctl start php73-php-fpm
[root@wulaoer ~]# curl http://10.211.55.5:8011/index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<style type="text/css">
body {background-color: #fff; color: #222; font-family: sans-serif;}
pre {margin: 0; font-family: monospace;}
a:link {color: #009; text-decoration: none; background-color: #fff;}
a:hover {text-decoration: underline;}
table {border-collapse: collapse; border: 0; width: 934px; box-shadow: 1px 2px 3px #ccc;}
.center {text-align: center;}
.center table {margin: 1em auto; text-alig
测试完成,问题解决。

您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏