首页 新闻 会员 周边

Nginx 代理出现问题

0
悬赏园豆:15 [已解决问题] 解决于 2020-03-07 16:02
error.log 出现这问题:
2020/03/07 13:52:47 [notice] 12156#10460: signal process started
2020/03/07 13:54:59 [error] 8940#7956: *33 upstream timed out
(10060: A connection attempt failed because the connected party
did not properly respond after a period of time, or established connection
failed because connected host has failed to respond) while connecting
to upstream, client: 127.0.0.1, server: localhost, request:
"GET /index.html HTTP/1.1", upstream: "http://192.108.1.102:8999/index.html",
host: "localhost:8086"



conf.配置如下
复制代码
 11 
 12 
 13 
 14    #                  '$status $body_bytes_sent "$http_referer" '
 15     
 16 
 17    # user  nobody;
 18     worker_processes  1;
 19    # error_log  logs/error.log;
 20    # error_log  logs/error.log  notice
 21    # error_log  logs/error.log  info;
 22 #  pid        logs/nginx.pid;
 23 events {
 24     worker_connections  1024;
 25 }
 26 http {
 27     include       mime.types;
 28     default_type  application/octet-stream;
 29 
 30     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
 31     #                  '$status $body_bytes_sent "$http_referer" '
 32     #                  '"$http_user_agent" "$http_x_forwarded_for"';
 33     #access_log  logs/access.log  main;
 34     sendfile        on;
 35     #tcp_nopush     on;
 36     #keepalive_timeout  0;
 37     keepalive_timeout  30;
 38     #gzip  on;
 39 
 40     upstream cgrain  { 
 41         server  192.108.1.102:8999 weight=1; #第一个测试网站
 42         server  192.108.1.102:8888 weight=3;  #第二个测试网站
 43     } 
 44 
 45     server {
 46         listen       8086;#这个原来是80端口,如果80已经被占用需要进行修改
 47         server_name  localhost;
 48 
 49         #charset koi8-r;
 50 
 51         #access_log  logs/host.access.log  main;
 52 
 53         location / {
 54             root   html;
 55             index  index.html index.htm;
 56             proxy_pass  http://cgrain; #反向代理指向地址        
 57 
 58             
 59         }
 60 
 61         #error_page  404              /404.html;
 62 
 63         # redirect server error pages to the static page /50x.html
 64         #
 65         error_page   500 502 503 504  /50x.html;
 66         location = /50x.html {
 67             root   html;
 68         }
 69 
 70         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
 71         #
 72         #location ~ \.php$ {
 73         #    proxy_pass   http://127.0.0.1;
 74         #}
 75 
 76         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 77         #
 78         #location ~ \.php$ {
 79         #    root           html;
 80         #    fastcgi_pass   127.0.0.1:9000;
 81         #    fastcgi_index  index.php;
 82         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 83         #    include        fastcgi_params;
 84         #}
 85 
 86         # deny access to .htaccess files, if Apache's document root
 87         # concurs with nginx's one
 88         #
 89         #location ~ /\.ht {
 90         #    deny  all;
 91         #}
 92     }
 93 
 94 
 95     # another virtual host using mix of IP-, name-, and port-based configuration
 96     #
 97     #server {
 98     #    listen       8000;
 99     #    listen       somename:8080;
100     #    server_name  somename  alias  another.alias;
101 
102     #    location / {
103     #        root   html;
104     #        index  index.html index.htm;
105     #    }
106     #}
107 
108 
109     # HTTPS server
110     #
111     #server {
112     #    listen       443 ssl;
113     #    server_name  localhost;
114 
115     #    ssl_certificate      cert.pem;
116     #    ssl_certificate_key  cert.key;
117 
118     #    ssl_session_cache    shared:SSL:1m;
119     #    ssl_session_timeout  5m;
120 
121     #    ssl_ciphers  HIGH:!aNULL:!MD5;
122     #    ssl_prefer_server_ciphers  on;
123 
124     #    location / {
125     #        root   html;
126     #        index  index.html index.htm;
127     #    }
128     #}
129 
130 }
复制代码

 

 不知道是不是我在  conf文件夹下面 随手复制nginx.conf,然后在这个复制的文件基础上重命名的原因...

问题补充:

IIS进行 telnet:

这里发现IP 弄错了,然后我改成iis 能够正常访问的ip, 但是还是上面的那种情况, telnet 不通

nginx 还是 504错误:

永远跟党走i的主页 永远跟党走i | 小虾三级 | 园豆:1519
提问于:2020-03-07 14:05
< >
分享
最佳答案
0

... 各位大佬,不好意思,我的原因

前面确实telnet 一直不通( IP 一半写对了,一般写错了,这是一个原因 ), 后面   又重新 搭了一个web站点 + 电脑重启

该通的都通了.

192.168.1.102:8999 192.168.1.102:8888 只有这两个没通了

 我后面仔细想了想,为什么这两个端口没有通 ,而8086端口能通了
 误解了Nginx 的意思,后面想了想   

server  {  

listen 8086 这里是你要监听的端口

...

server 192.108.1.102:8999 weight=1;  这里是要指向你网站的端口 

8999  我根本就没有配置.....!!!!

现在我配置了一下,好了, Telnet 也通了


谢谢各位大佬,谢谢 @dudu

自己粗心了

永远跟党走i | 小虾三级 |园豆:1519 | 2020-03-07 16:01
其他回答(3)
0

他错误不是说你的host有问题么,nginx机器上 curl http://192.108.1.102:8999/index.html 看看

收获园豆:3
czd890 | 园豆:14412 (专家六级) | 2020-03-07 14:12

这个我改了,刚开始是用 localhost  ,差不多也是这个问题,然后使用192.0.0.1 ,也是这个问题 反正都是504网关错误...

支持(0) 反对(0) 永远跟党走i | 园豆:1519 (小虾三级) | 2020-03-07 14:43
0

用 telnet 命令测试一下 upstream 能否连上

telnet 192.108.1.102 8999
telnet 192.108.1.102 8888
收获园豆:10
dudu | 园豆:31007 (高人七级) | 2020-03-07 14:46

访问不了,而且  我测试发布在iis 上的也不行,我把问题补充一下

支持(0) 反对(0) 永远跟党走i | 园豆:1519 (小虾三级) | 2020-03-07 15:12

@Cgrain: 先让它们可以访问

支持(0) 反对(0) dudu | 园豆:31007 (高人七级) | 2020-03-07 15:15

@dudu: 我iis +浏览器能够访问的,用你这个命令他也提示连接失败,但是浏览器可以正常访问

支持(0) 反对(0) 永远跟党走i | 园豆:1519 (小虾三级) | 2020-03-07 15:22

@Cgrain: 浏览器访问的是 http://192.108.1.102:8999

支持(0) 反对(0) dudu | 园豆:31007 (高人七级) | 2020-03-07 15:27

@dudu: 是的 , IP 改成 192.168.1.102 telnet 也是不通

支持(0) 反对(0) 永远跟党走i | 园豆:1519 (小虾三级) | 2020-03-07 15:29

@dudu: 现在 我telnet iis 发布的web 程序,能够连上,但是 192.168.1.102:8999 ,192.168.1.102:8888 还是失败

支持(0) 反对(0) 永远跟党走i | 园豆:1519 (小虾三级) | 2020-03-07 15:37

@dudu: 刚刚电脑重新启动了 192.168.1.102:8086 能够连接, 但是
server 192.168.1.102:8999 weight=1; #第一个测试网站
server 192.168.1.102:8888 weight=3; #第二个测试网站
这两个死活不通
错误日志 :
2020/03/07 15:30:42 [notice] 17072#20568: signal process started
2020/03/07 15:32:37 [notice] 14244#5148: signal process started

支持(0) 反对(0) 永远跟党走i | 园豆:1519 (小虾三级) | 2020-03-07 15:41
0

192.168.1.102:8999 192.168.1.102:8888 直接访问这两个看通不通

收获园豆:2
风行天下12 | 园豆:3867 (老鸟四级) | 2020-03-07 15:49

... 对不起,我蠢了,我的原因

支持(0) 反对(0) 永远跟党走i | 园豆:1519 (小虾三级) | 2020-03-07 15:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册