【问题标题】:Nginx + php-fpm 502 bad gateway only on domainNginx + php-fpm 502 bad gateway 仅在域上
【发布时间】:2019-12-17 19:15:32
【问题描述】:

我有centos服务器,它配置了php和nginx,当我重新启动时,当我输入ip地址而不是域地址时,php文件没有执行,它工作正常

虚拟主机的 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;
  }
}

【问题讨论】:

  • 你能发布你的 nginx 配置吗?
  • @Araw,配置已添加,请检查相同
  • 你只加server_name www.domainname.com;,你需要加server_name your ip address here;

标签: php nginx nginx-config


【解决方案1】:

如果你想通过ip地址访问你的服务器,你需要在你的nginx conf中添加你的ip地址。

server_name your_ip_address;

【讨论】:

    猜你喜欢
    • 2015-05-17
    • 2014-03-27
    • 2014-10-17
    • 2018-09-12
    • 2019-03-07
    • 2017-05-03
    • 1970-01-01
    • 2015-05-25
    • 1970-01-01
    相关资源
    最近更新 更多