client_max_body_size 1000m;
client_header_timeout 1m;
client_body_timeout 5m;
proxy_connect_timeout 60s;
proxy_read_timeout 1m;
proxy_send_timeout 1m;
send_timeout 20s;每个参数的意思:
client_max_body_size
限制请求体的大小,若超过所设定的大小,返回413错误。
client_header_timeout
读取请求头的超时时间,若超过所设定的大小,返回408错误。
client_body_timeout
读取请求实体的超时时间,若超过所设定的大小,返回413错误。
proxy_connect_timeout
http请求无法立即被容器(tomcat, netty等)处理,被放在nginx的待处理池中等待被处理。
此参数为等待的最长时间,默认为60秒,官方推荐最长不要超过75秒。
proxy_read_timeout
http请求被容器(tomcat, netty等)处理后,nginx会等待处理结果,也就是容器返回的response。
此参数即为服务器响应时间,默认60秒。
proxy_send_timeout
http请求被服务器处理完后,把数据传返回给Nginx的用时,默认60秒。
send_timeout
服务器把结果返回的时间
大文件上传费时的是文件到代理服务器(Nginx)的时间,所以
proxy_xxx相关的时间不用配置的过长
upstream filetest_psvmc {
server 127.0.0.1:8905;
}
server {
listen 80;
server_name filetest.psvmc.cn;
listen 443;
ssl on;
ssl_certificate /etc/nginx/cert/psvmc.pem;
ssl_certificate_key /etc/nginx/cert/psvmc.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 /static {
index index.html;
root /data/wwwjarapi/8905xhkjfileapitest/;
}
location / {
proxy_pass http://filetest_psvmc/;
proxy_cookie_path / /;
proxy_redirect / /;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 1000m;
client_body_buffer_size 128k;
client_body_timeout 5m;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_buffer_size 64k;
proxy_buffers 8 64k;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
send_timeout 20s;
}
}location [=|~|~*|^~|@] pattern{……}示例
location = / {
# 只匹配 / 的查询.
[ configuration A ]
}
location / {
# 匹配任何以 / 开始的查询,但是正则表达式与一些较长的字符串将被首先匹配。
[ configuration B ]
}
location ^~ /images/ {
# 匹配任何以 /images/ 开始的查询并且停止搜索,不检查正则表达式。
[ configuration C ]
}
location ~* \.(gif|jpg|jpeg)$ {
# 匹配任何以gif, jpg, or jpeg结尾的文件,但是所有 /images/ 目录的请求将在Configuration C中处理。
[ configuration D ]
}
location ~*.(gif|jpg|swf)$ {
valid_referers none blocked image.psvmc.cn static.psvmc.cn;
if ($invalid_referer) {
#防盗链
rewrite ^/ http://$host/daolian.png;
}
[ configuration E ]
}各请求的处理如下例:
查找顺序和优先级
=的精确匹配优先^~修饰符的,开头匹配~ 或~\* 修饰符的,如果正则表达式与URI匹配location /img/ {
alias /var/www/image/;
}
#若按照上述配置的话,则访问/img/目录里面的文件时,ningx会自动去/var/www/image/目录找文件
location /img/ {
root /var/www/image;
}
#若按照这种配置的话,则访问/img/目录下的文件时,nginx会去/var/www/image/img/目录下找文件。]alias是一个目录别名的定义,root则是最上层目录的定义。
还有一个重要的区别是alias后面必须要用/结束,否则会找不到文件的 而root则可有可无