nginx的文件提示502就是服务没有启动,这里不管是php还是java。出现502的问题都是服务没有启动,下面浮现一下,首先在nginx的配置文件里写了一个php版本的文件。
[root@wulaoer ~]# cat /home/wwwroot/default/index.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
502 Bad Gateway502 Bad Gateway
启动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
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
测试完成,问题解决。