简体   繁体   中英

Nginx + php-fpm 502 bad gateway only on domain

I have centos server, it's configured with php and nginx, when I restart that time php file is not executing when i type ip address instead of domain address, it's working fine

nginx config for vhost

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;
  }
}

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

server_name your_ip_address;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM