nginx调优

proxy_read_timeout

proxy模块的proxy_read_timeout
syntax: proxy_read_timeout the_time

default: proxy_read_timeout 60

context: http, server, location

This directive sets the read timeout for the response of the proxied server. It determines how long NGINX will wait to get the response to a request. The timeout is established not for entire response, but only between two operations of reading.

In contrast to proxy_connect_timeout, this timeout will catch a server that puts you in it's connection pool but does not respond to you with anything beyond that. Be careful though not to set this too low, as your proxy server might take a longer time to respond to requests on purpose (e.g. when serving you a report page that takes some time to compute). You are able though to have a different setting per location, which enables you to have a higher proxy_read_timeout for the report page's location.

If the proxied server nothing will communicate after this time, then nginx is shut connection.
 

上面意思是,如果后端服务处理请求所需的时间比较长,比如加载大量的数据,生成报表等操作,文件服务器传输文件等,proxy_read_timeout 要设置超过这个时间,否则出现504状态码(网关错误)。proxy_read_timeout设置大一点即可,再有一点就是,这个时间设置,并不是整个响应周期的时间,有些响应分好几次传输,该时间就是两次成功传输间的时间。

当请求大文件时,后端生成资源比较慢的状态下,就直接更改该选项即可。

proxy_send_timeout time

Syntax:    proxy_send_timeout time;
Default:    proxy_send_timeout 60s;
Context:    http, server, location

Sets a timeout for transmitting a request to the proxied server. The timeout is set only between two successive write operations, not for the transmission of the whole request. If the proxied server does not receive anything within this time, the connection is closed.

这是nginx代理服务器向后端服务发起请求的超时时间,请求比较大时,会依次发送,在规定的时间内,服务端没有收到任何请求,那么连接就会关闭。

underscores_in_headers on

nginx代理默认会把header中参数的 "_" 下划线去掉,所以后台服务器后就获取不到带"_"线的参数名。

underscores_in_headers on; 
#该属性默认为off,表示如果header name中包含下划线,则忽略掉。

请求头如果有下划线,我们将该选项设置为on即可。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当涉及到Nginx和JVM的调优时,我们可以从两个方面来讨论。 首先是Nginx调优Nginx是一个高性能的Web服务器和反向代理服务器,以下是一些常见的Nginx调优方法: 1. 调整worker_processes和worker_connections:根据服务器的硬件配置和负载情况,适当调整worker_processes(工作进程数)和worker_connections(每个工作进程的最大连接数)参数,以提高并发处理能力。 2. 启用gzip压缩:开启gzip压缩可以减小传输的数据量,提高网站的响应速度。 3. 调整缓冲区大小:通过调整proxy_buffer_size、proxy_buffers和proxy_busy_buffers_size等参数,可以优化Nginx对后端服务器的请求和响应的缓冲区管理,提高性能。 4. 使用缓存:使用Nginx的缓存功能可以减轻后端服务器的负载,提高响应速度。可以通过配置proxy_cache和相关参数来启用缓存。 5. 负载均衡:通过配置upstream模块,可以实现Nginx的负载均衡功能,将请求分发到多个后端服务器上,提高系统的可用性和性能。 接下来是JVM的调优。JVM是Java虚拟机的缩写,以下是一些常见的JVM调优方法: 1. 调整堆内存大小:通过调整-Xms和-Xmx参数,可以设置JVM的初始堆大小和最大堆大小,以适应应用程序的内存需求。 2. 设置垃圾回收器:根据应用程序的特点和性能需求,选择合适的垃圾回收器,如Serial GC、Parallel GC、CMS GC或G1 GC,并通过相关参数进行配置。 3. 调整线程数:通过调整-Xss参数,可以设置线程栈的大小,以及通过调整-XX:ParallelGCThreads参数来设置并行垃圾回收线程数,以提高并发处理能力。 4. 监控和分析工具:使用JVM提供的监控和分析工具,如jstat、jconsole、jvisualvm等,可以实时监控JVM的运行状态和性能指标,帮助定位性能瓶颈和优化机会。 5. 代码优化:通过对代码进行优化,如减少对象的创建、避免过多的同步、合理使用缓存等,可以减少JVM的负载,提高性能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值