Nginx + php-fpm 502错误的网关仅在域上

时间:2019-08-10 07:44:55

标签: php nginx nginx-config

我有centos服务器,它是用php和nginx配置的,当我重新启动该时间时,当我键入ip地址而不是域地址时,php文件没有执行,

vhost的nginx配置

server {
  listen 80;

  server_name domainname.com;
  rewrite ^ $scheme://www.domainname.com$request_uri? permanent;
}

server {
  listen 80;

  server_name www.domainname.com;
  if ($http_x_forwarded_proto = 'http'){
    return 301 https://$host$request_uri;
  }

  root /home/global/domainname.com;
  index index.php index.html index.htm;

  access_log  /home/global/logs/access.log;
  error_log   /home/global/logs/error.log;

  location = /favicon.ico {
    log_not_found off;
  }
  location ~ \.php$ {
fastcgi_intercept_errors      on;
#proxy_ignore_client_abort on;
      #fastcgi_pass   127.0.0.1:9000;
      #fastcgi_index  index.php;
      #fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      #include  fastcgi_params;
fastcgi_pass  127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME  /home/global/domainname.com$fastcgi_script_name;
            include        /etc/nginx/fastcgi_params;
  }
}

1 个答案:

答案 0 :(得分:0)

如果要通过IP地址访问服务器,则需要在Nginx conf中将IP地址添加到服务器。

server_name your_ip_address;