最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]nginx页面无法访问:502 Bad Gateway nginx/1.0.15

nginx crifan 9639浏览 0评论

折腾:

[记录]把服务器的IP地址映射到某二级域名http://hd.isip.cn

期间,

➜  conf.d cat default.conf.bk
server {
    listen       80;
    server_name  localhost;
    #server_name 115.29.173.126;
    #server_name hd.webonn.com;
    #server_name localhost;
    #server_name 127.0.0.1;
    access_log  /var/log/nginx/access.log;
    error_log  /var/log/nginx/error.log;
    location / {
        proxy_pass         http://127.0.0.1:8080/;
        #proxy_redirect     off;
        proxy_set_header   Host                 $host;
        proxy_set_header   X-Real-IP            $remote_addr;
        #proxy_set_header   X-Forwarded-For      $proxy_add_x_forwarded_for;
        #proxy_set_header   X-Forwarded-Proto    $scheme;
    }
}

http://115.29.173.126

http://hd.webonn.com

对应的log:

➜  conf.d netstat -tupln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:10022               0.0.0.0:*                   LISTEN      17286/docker-proxy  
tcp        0      0 0.0.0.0:9000                0.0.0.0:*                   LISTEN      19706/docker-proxy  
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      17220/mysqld        
tcp        0      0 127.0.0.1:6379              0.0.0.0:*                   LISTEN      19659/redis-server  
tcp        0      0 0.0.0.0:9003                0.0.0.0:*                   LISTEN      19669/docker-proxy  
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      19128/nginx         
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1335/sshd           
tcp        0      0 0.0.0.0:3000                0.0.0.0:*                   LISTEN      17240/docker-proxy  
tcp        0      0 0.0.0.0:8088                0.0.0.0:*                   LISTEN      29962/docker-proxy  
tcp        0      0 0.0.0.0:5432                0.0.0.0:*                   LISTEN      18421/docker-proxy  
tcp        0      0 0.0.0.0:8000                0.0.0.0:*                   LISTEN      19505/docker-proxy  
tcp        0      0 0.0.0.0:32771               0.0.0.0:*                   LISTEN      8748/docker-proxy   
tcp        0      0 0.0.0.0:32772               0.0.0.0:*                   LISTEN      8782/docker-proxy   
udp        0      0 192.168.42.1:123            0.0.0.0:*                               1346/ntpd           
udp        0      0 115.29.173.126:123          0.0.0.0:*                               1346/ntpd           
udp        0      0 10.161.170.247:123          0.0.0.0:*                               1346/ntpd           
udp        0      0 127.0.0.1:123               0.0.0.0:*                               1346/ntpd           
udp        0      0 0.0.0.0:123                 0.0.0.0:*                               1346/ntpd           
➜  conf.d tail /var/log/nginx/error.log
2016/09/09 11:30:12 [error] 19041#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 114.216.25.29, server: localhost, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "hd.webonn.com"
2016/09/09 11:30:16 [error] 19041#0: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 114.216.25.29, server: localhost, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "115.29.173.126"
2016/09/09 11:30:26 [error] 19041#0: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 114.216.25.29, server: localhost, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "hd.webonn.com"
2016/09/09 11:30:29 [error] 19041#0: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 114.216.25.29, server: localhost, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "115.29.173.126"
2016/09/09 11:30:29 [error] 19041#0: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 114.216.25.29, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8080/favicon.ico", host: "115.29.173.126", referrer: "http://115.29.173.126/"
2016/09/09 11:30:30 [error] 19041#0: *11 connect() failed (111: Connection refused) while connecting to upstream, client: 119.147.146.189, server: localhost, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "115.29.173.126"
2016/09/09 11:31:07 [error] 19041#0: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 114.216.25.29, server: localhost, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "115.29.173.126"
2016/09/09 11:31:08 [error] 19041#0: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 114.216.25.29, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8080/favicon.ico", host: "115.29.173.126", referrer: "http://115.29.173.126/"
2016/09/09 11:33:18 [error] 19129#0: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 114.216.25.29, server: localhost, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "115.29.173.126"
2016/09/09 11:33:18 [error] 19129#0: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 114.216.25.29, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8080/favicon.ico", host: "115.29.173.126", referrer: "http://115.29.173.126/"

后来,把default.conf改为默认的内容:

➜  conf.d cat default.conf       
server {
    listen       80;
    server_name  localhost;
    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}
    # deny access to .htaccess files, if Apache’s document root
    # concurs with nginx’s one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

然后就可以正常访问了:

->

但是对于我之前的:

访问:

http://hd.webonn.com

会跳转到:

我的Flask的里面去处理

-》

之前的话,应该会提示用微信登陆:

最后,是用了,和之前类似的配置:

➜  conf.d pwd
/etc/nginx/conf.d
➜  conf.d cat default.conf
server {
    listen       80;
    server_name  localhost;
    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;
        location / {
        proxy_pass         http://127.0.0.1:8080/;
        #proxy_redirect     off;
        proxy_set_header   Host                 $host;
        proxy_set_header   X-Real-IP            $remote_addr;
        #proxy_set_header   X-Forwarded-For      $proxy_add_x_forwarded_for;
        #proxy_set_header   X-Forwarded-Proto    $scheme;
    }
    #location / {
    #    root   /usr/share/nginx/html;
    #    index  index.html index.htm;
    #}
    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}
    # deny access to .htaccess files, if Apache’s document root
    # concurs with nginx’s one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
➜  conf.d

然后页面看可以访问了:

http://115.29.173.126

http://hd.webonn.com

转载请注明:在路上 » [已解决]nginx页面无法访问:502 Bad Gateway nginx/1.0.15

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.195 seconds, using 22.18MB memory