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 [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,添加如下信息

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           4 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 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

原文地址:https://www.cnblogs.com/2012blog/p/9431736.html

时间: 2024-07-29 22:20:38

Nginx反向代理报504超时错误的相关文章

nginx反向代理报错400

当用nginx做负载均衡的时候,nginx的配置文件如下: upstream server_pools { server 10.0.0.7:80 weight=1; server 10.0.0.8:80 weight=1; 当客户端访问时出现报错如下: [[email protected] ~]# curl www.hahaetiantian.org <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html>

nginx反向代理 报错:Error during WebSocket handshake: Unexpected response code: 403

遇到nginx报错:websocket wss failed: Error during WebSocket handshake: Unexpected response code: 403 server { listen 6340; location / { proxy_pass http://web; proxy_http_version 1.1; #Nginx在与Node后端通信时使用HTTP/1.1,是WebSockets所必需的 proxy_set_header Origin '';

nginx反向代理后端IIS持续报错504

故障:使用nginx反向代理后端的IIS服务器出现报错504 gateway time-out 在网上查找修改buffer等内容无法解决 在nginx的配置文件中 event{ accept_mutex off; } 问题解决

nginx 反向代理 后端 499 错误

499错误是什么 ngx_string(ngx_http_error_495_page), /* 495, https certificate error */ ngx_string(ngx_http_error_496_page), /* 496, https no certificate */ ngx_string(ngx_http_error_497_page), /* 497, http to https */ ngx_string(ngx_http_error_404_page), /

Nginx反向代理Tomcat静态资源无法加载以及请求链接错误

 在使用Nginx实现Tomcat的负载均衡的时候,项目发布到了Tomcat,Nginx也配置好了, 当访问的时候发现了与预期不符 表现为: 静态资源加载失败 链接跳转地址错误 下面是我错误的配置文件 #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; e

Nginx反向代理,负载均衡,redis session共享,keepalived高可用

相关知识自行搜索,直接上干货... 使用的资源: nginx主服务器一台,nginx备服务器一台,使用keepalived进行宕机切换. tomcat服务器两台,由nginx进行反向代理和负载均衡,此处可搭建服务器集群. redis服务器一台,用于session的分离共享. nginx主服务器:192.168.50.133 nginx备服务器:192.168.50.135 tomcat项目服务器1:192.168.50.137 tomcat项目服务器2:192.168.50.139 redis服

搭建nginx反向代理用做内网域名转发

基于域名的7层转发的实现(NAT+反向代理) 在实际办公网中,因为出口IP只有一个,要实现对外提供服务的话就必须得做端口映射,如果有多个服务要对外开放的话,这只能通过映射不同端口来区分,这在实际使用过程中非常的痛苦(记忆困难.一一对应关系也没有规律.访问的时候还得加端口),这个痛苦的问题用表格的形式来形象的描述如下: Public IP Public Port Number Internal IP Internal Port Number Note 1.1.1.1 80 192.168.1.10

nginx反向代理tomacat+keepalived实现动静分离、负载均衡、高可用

本文的动静分离主要是通过nginx+tomcat来实现,其中nginx处理图片.html.JS.CSS等静态文件,tomcat处理jsp.servlet等动态请求 服务器名称                                 系统版本                           预装软件                     IP地址 Nginx服务器                             CentOS 7 最小安装              Nginx

nginx反向代理-后端服务器组设置

nginx服务器的反向代理时其最常用的重要功能之一,在实际工作中应用广泛,涉及的配置指令也比较多.下面会尽量详细地介绍对应的指令,及其使用状态. 反向代理一般是互联网需要向内网拉取资源,比如访问一个web网站时,互联网应用通过一个代理服务器到后面真实的web服务器拉取应用所需的数据. nginx服务器反向代理用到的指令如果没有特别的说明,原则上可以出现在nginx配置文件的http块,server块和location块中,但是同正向代理一样,一般是搭建在nginx服务器中单独配置一个server