AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 946614
Accepted
Daniel
Daniel
Asked: 2018-12-26 17:19:59 +0800 CST2018-12-26 17:19:59 +0800 CST 2018-12-26 17:19:59 +0800 CST

502 由于未定义索引而导致网关错误?

  • 772

在我的站点中,执行以下配置后,我得到一个 502 bad gateway:

# Default server configuration
  2 #
  3  server {
  4         listen 80;
  5         listen [::]:80;
  6         server_name microurb.club;
  7         return 301 http://www.microurb.club;
  8  }
  9
 10  server {
 11         listen 80;
 12         listen [::]:80;
 13
 14   # SSL configuration
 15   #
 16   # listen 443 ssl default_server;
 17   # listen [::]:443 ssl default_server;
 18   #
 19   # include snippets/snakeoil.conf;
 20
 21   root /var/www/microurb.com/public_html;
 22
 23   # Add index.php to the list if you are using PHP
 24  index index.php index.html index.htm index.nginx-debian.htm;
 25
 26  server_name  www.microurb.club;
 27 ·
 28  include global/restrictions.conf;
 29  include global/wordpress.conf;
 30 ·
 31 # location / {
 32 #   # First attempt to serve request as file, then
 33 #   # as directory, then fall back to displaying a 404.
 34 #   try_files $uri $uri/ =404;
 35 # }
 36
 37   location ~ \.php$ {
 38     include snippets/fastcgi-php.conf;
 39     fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
 40   }
 41
 42   # Allow access to the ACME Challenge directory
 43       location ~ /\.well-known\/acme-challenge {
 44         allow all;
 45   }
 46
 47   include custom_config_files/x_protection.conf;
 48 }
 49
 50 server {

 51         listen 443 ssl http2;
 52         listen [::]:443 ssl http2;
 53         server_name microurb.club;
 54         return 301 https://www.microurb.club;
 55         include ssl/ssl_general.conf;
 56         include ssl/ssl_microurb.com.conf;
 57 }
 58
 59 server {
 60         listen 443 ssl http2;
 61         listen [::]:443 ssl http2;
 62         server_name www.microurb.club;
 63
 64         include ssl/ssl_general.conf;
 65         include ssl/ssl_microurb.com.conf;
 66
 67         root /var/www/microurb.com/public_html;
 68
 69         # Add index.php to the list if you are using PHP
 70         index index.html index.php;
 71
 72         location ~ \.php$ {
 73           include snippets/fastcgi-php.conf;
 74           fastcgi_pass unix:/var/run/php7.0-fpm.sock;
 75         }
 76
 77         include custom_config_files/x_protection.conf;
 78 }
 79

我做了一个:

sudo tail -30 /var/log/nginx/error.log

并收到以下错误,但我不知道它们是什么意思:

PHP message: PHP Notice:  Undefined index: success in /var/www/microurb.com/public_html/index.php on line 295" while reading upstream, client: 24.55.9.54, server: www.microurb.club, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "www.microurb.club"
2018/12/25 20:07:05 [crit] 18408#18408: *40 connect() to unix:/var/run/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 24.55.9.54, server: www.microurb.club, request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/var/run/php7.0-fpm.sock:", host: "www.microurb.club"
2018/12/25 20:07:06 [error] 18408#18408: *40 open() "/var/www/microurb.com/public_html/favicon.ico" failed (2: No such file or directory), client: 24.55.9.54, server: www.microurb.club, request: "GET /favicon.ico HTTP/2.0", host: "www.microurb.club", referrer: "https://www.microurb.club/"
2018/12/25 20:07:10 [crit] 18408#18408: *40 connect() to unix:/var/run/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 24.55.9.54, server: www.microurb.club, request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/var/run/php7.0-fpm.sock:", host: "www.microurb.club"
2018/12/25 20:07:20 [crit] 18408#18408: *40 connect() to unix:/var/run/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 24.55.9.54, server: www.microurb.club, request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/var/run/php7.0-fpm.sock:", host: "www.microurb.club"

我相信问题根源于我上面的配置,但我不确定在哪里。当我尝试取消注释此块时:

 31 # location / {
 32 #   # First attempt to serve request as file, then
 33 #   # as directory, then fall back to displaying a 404.
 34 #   try_files $uri $uri/ =404;
 35 # }

运行后我得到一个错误,sudo nginx -t说我有nginx: [emerg] duplicate location "/" in /etc/nginx/sites-enabled/microurb.com:31,但我只有一个。不知道为什么我会收到那个错误。

nginx
  • 1 1 个回答
  • 318 Views

1 个回答

  • Voted
  1. Best Answer
    kolbyjack
    2018-12-27T08:40:27+08:002018-12-27T08:40:27+08:00

    第 39 行和第 74 行的 fastcgi_pass 路径不匹配(74 缺少 /php)。因为它抱怨第 74 行的路径,所以将其更改为匹配第 39 行:

    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    
    • 1

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve