Nginx 代理出现问题

2020-03-07 15:26发布

问题:

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,然后在这个复制的文件基础上重命名的原因...

回答1:

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

前面确实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

自己粗心了



回答2:

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



回答3:

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

telnet 192.108.1.102 8999
telnet 192.108.1.102 8888


回答4:

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



标签: nginx