Nginx反向代理报504超时错误

 

nginx+tomcat

后端为tomcat,nginx代理报504超时错误。

问题描述:

#错误
1.198.17.123 - - [06/Jul/2018:01:48:57 +0000] "POST /mapbj3/getticket HTTP/1.1" 504 537 "https://XXXXXXXXXX.com/walkcode3/index.html?openId=oB6UW0cF3Z_dnYXnz4tG4OFt7Rt0" "Mozilla/5.0 (Linux; Android 8.1; PACM00 Build/O11019; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.143 Crosswalk/24.53.595.0 XWEB/155 MMWEBSDK/19 Mobile Safari/537.36 MicroMessenger/6.6.6.1300(0x26060638) NetType/WIFI Language/zh_CN MicroMessenger/6.6.6.1300(0x26060638) NetType/WIFI Language/zh_CN miniProgram" "-"
2018/07/06 01:48:57 [error] 6#6: *2573 upstream timed out (110: Connection timed out) while connecting to upstream, client: 1.198.17.123, server: , request: "POST /mapbj3/getticket HTTP/1.1", upstream: "http://123.149.236.180:8022/mapbj3//getticket", host: "XXXXXXXX.com", referrer: "https://XXXXXXX.com/walkcode3/index.html?openId=oB6UW0cF3Z_dnYXnz4tG4OFt7Rt0"

1、项目本地访问没问题,通过nginx访问报504错误;

2、重启nginx后正常,反复发生,其它项目代理没有问题;

3、搜索了一大推”NGINX 504 Gateway Time-out tomcat”,都是与php有关的,而默认优化的就是php配置的;

问题处理:

修改/etc/nginx/nginx.conf,添加如下信息

# cat /etc/nginx/nginx.conf
user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                      ‘$status $body_bytes_sent "$http_referer" ‘
                      ‘"$http_user_agent" "$http_x_forwarded_for"‘;

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
    #用于tomcat反向代理,解决nginx 504错误 
    proxy_connect_timeout   300; 
    proxy_send_timeout      300; 
    proxy_read_timeout      300; 
    proxy_buffer_size       16k; 
    proxy_buffers           4 64k; 
    proxy_busy_buffers_size 128k; 
    proxy_temp_file_write_size 128k;
    # ps:以timeout结尾配置项时间要配置大点
}

nginx+php(未验证)

问题如上,问题处理添加如下内容

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                      ‘$status $body_bytes_sent "$http_referer" ‘
                      ‘"$http_user_agent" "$http_x_forwarded_for"‘;

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
    #用于php反向代理,解决nginx 504错误 
    #以fastcgi_*配置项是php用的    
    fastcgi_connect_timeout 1000;
    fastcgi_send_timeout 1000;
    fastcgi_read_timeout 1000;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 8 128k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    fastcgi_intercept_errors on;
}

参考文档

https://blog.csdn.net/lcj_star/article/details/76672748https://www.iyunv.com/thread-319236-1-1.html

nginx+tomcat

后端为tomcat,nginx代理报504超时错误。

问题描述:

 
 
 
 
 
 
Default
 
1
2
3
#错误
1.198.17.123 [06/Jul/2018:01:48:57 +0000"POST /mapbj3/getticket HTTP/1.1" 504 537 "https://XXXXXXXXXX.com/walkcode3/index.html?openId=oB6UW0cF3Z_dnYXnz4tG4OFt7Rt0" "Mozilla/5.0 (Linux; Android 8.1; PACM00 Build/O11019; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.143 Crosswalk/24.53.595.0 XWEB/155 MMWEBSDK/19 Mobile Safari/537.36 MicroMessenger/6.6.6.1300(0x26060638) NetType/WIFI Language/zh_CN MicroMessenger/6.6.6.1300(0x26060638) NetType/WIFI Language/zh_CN miniProgram" "-"
2018/07/06 01:48:57 [error6#6: *2573 upstream timed out (110: Connection timed out) while connecting to upstream, client: 1.198.17.123, server: , request: "POST /mapbj3/getticket HTTP/1.1", upstream: "http://123.149.236.180:8022/mapbj3//getticket", host: "XXXXXXXX.com", referrer: "https://XXXXXXX.com/walkcode3/index.html?openId=oB6UW0cF3Z_dnYXnz4tG4OFt7Rt0"

1、项目本地访问没问题,通过nginx访问报504错误;

2、重启nginx后正常,反复发生,其它项目代理没有问题;

3、搜索了一大推”NGINX 504 Gateway Time-out tomcat”,都是与php有关的,而默认优化的就是php配置的;

问题处理:

修改/etc/nginx/nginx.conf,添加如下信息

 
 
 
 
 
Default
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# cat /etc/nginx/nginx.conf
user  nginx;
worker_processes  1;
 
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
 
 
events {
    worker_connections  1024;
}
 
 
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
 
    log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                      ‘$status $body_bytes_sent "$http_referer" ‘
                      ‘"$http_user_agent" "$http_x_forwarded_for"‘;
 
    access_log  /var/log/nginx/access.log  main;
 
    sendfile        on;
    #tcp_nopush     on;
 
    keepalive_timeout  65;
 
    #gzip  on;
 
    include /etc/nginx/conf.d/*.conf;
    #用于tomcat反向代理,解决nginx 504错误 
    proxy_connect_timeout   300
    proxy_send_timeout      300
    proxy_read_timeout      300
    proxy_buffer_size       16k
    proxy_buffers           64k
    proxy_busy_buffers_size 128k
    proxy_temp_file_write_size 128k;
    # ps:以timeout结尾配置项时间要配置大点
}

nginx+php(未验证)

问题如上,问题处理添加如下内容

 
 
 
 
 
Default
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
user  nginx;
worker_processes  1;
 
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
 
 
events {
    worker_connections  1024;
}
 
 
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
 
    log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                      ‘$status $body_bytes_sent "$http_referer" ‘
                      ‘"$http_user_agent" "$http_x_forwarded_for"‘;
 
    access_log  /var/log/nginx/access.log  main;
 
    sendfile        on;
    #tcp_nopush     on;
 
    keepalive_timeout  65;
 
    #gzip  on;
 
    include /etc/nginx/conf.d/*.conf;
    #用于php反向代理,解决nginx 504错误 
    #以fastcgi_*配置项是php用的    
    fastcgi_connect_timeout 1000;
    fastcgi_send_timeout 1000;
    fastcgi_read_timeout 1000;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 128k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    fastcgi_intercept_errors on;
}

参考文档

https://blog.csdn.net/lcj_star/article/details/76672748https://www.iyunv.com/thread-319236-1-1.html

 
 
 
 

相关推荐