nginx+tomcat nginx 504 Gateway Time-out的方法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx+tomcat nginx 504 Gateway Time-out的方法相关的知识,希望对你有一定的参考价值。
参考技术A 解决 nginx 504 Gateway Time-out的方法应用是nginx+ tomcat 7
根据这个错误,是因为tomcat没有及时回应nginx,导致错误.
先使用 fiddler 将页面的请求抓出来.
找到504的请求.然后查找原因.
因为这个请求时间比较长,只有90秒.
所以修改
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
修改成
proxy_connect_timeout 18000; ##修改成半个小时
proxy_send_timeout 18000;
proxy_read_timeout 18000;
http://www.07net01.com/zhishi/188736.html
https://blog.csdn.net/e_wsq/article/details/76599391
配置nginx + https + tomcat/ nginx + https + jar/ nginx + https + tomcat + war
1.nginx + https + tomcat
nginx配置:
server {
listen 443;
server_name www.example.com; #域名
ssl on;
#index index.html index.htm;
ssl_certificate cert/1523584742511.pem; #证书
ssl_certificate_key cert/1523584732510.key; #证书
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
root "C:/Program Files/apache-tomcat-8.5.30/webapps"; #tomcat路径
index index.html index.htm;
}
}
server {
listen 80;
server_name www.example.com; #域名
rewrite ^(.*)$ https://$host$1 permanent; #将80端口的http转向443端口的https
}
2.nginx + https + jar
spring boot打包的jar,本身已包含内置tomcat可以独立运行,所以在任意地方启动服务后
现在spring boot项目的propertis里增加配置:
server.use-forward-headers=true
server.tomcat.remote-ip-header=x-forwarded-for
server.tomcat.protocol-header=x-forwarded-proto
server.tomcat.port-header=X-Forwarded-Port
nginx配置:
server {
listen 443;
server_name www.example.com;
ssl on;
#index index.html index.htm;
ssl_certificate cert/1523584742511.pem; #证书
ssl_certificate_key cert/1523234742510.key; #证书
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://127.0.0.1:9001/your-example-applet; #启动的jar服务名,就是那个properties里的server.context-path=
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
}
}
server {
listen 80;
server_name www.example.com;
rewrite ^(.*)$ https://$host$1 permanent;
}
3.nginx + https + tomcat + war
打war包时排除内置tomcat
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 用于war包时排除tomcat -->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 用于运行时使用但打war包时排除tomcat -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
nginx配置类似:
server {
listen 443;
server_name www.example.com;
ssl on;
#index index.html index.htm;
ssl_certificate cert/1523584742511.pem; #证书
ssl_certificate_key cert/1523583742510.key; #证书
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://127.0.0.1:9001/your-example-applet; #启动的jar服务名,就是那个properties里的server.context-path=
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
root "C:/Program Files/apache-tomcat-8.5.30/webapps"; #tomcat路径
index index.html index.htm;
}
}
server {
listen 80;
server_name www.example.com;
rewrite ^(.*)$ https://$host$1 permanent;
}
以上是关于nginx+tomcat nginx 504 Gateway Time-out的方法的主要内容,如果未能解决你的问题,请参考以下文章