问题描述
以下是我的Nginx配置
worker_processes 1;
events {
use epoll;
worker_connections 1024;
multi_accept on;
}
http
{
include mime.types;
default_type application/octet-stream;
log_format main '{"@timestamp":"$time_iso8601",'
'"host":"$server_addr",'
'"clientip":"$remote_addr",'
'"size":$body_bytes_sent,'
'"responsetime":$request_time,'
'"upstreamtime":"$upstream_response_time",'
'"upstreamhost":"$upstream_addr",'
'"http_host":"$host",'
'"url":"$uri",'
'"xff":"$http_x_forwarded_for",'
'"referer":"$http_referer",'
'"post_body":"$request_body",'
'"cookie":"$http_cookie",'
'"agent":"$http_user_agent",'
'"status":"$status"}';
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_names_hash_bucket_size 128;
server_names_hash_max_size 512;
keepalive_timeout 65;
client_header_timeout 15s;
client_body_timeout 15s;
send_timeout 60s;
client_body_buffer_size 512k;
client_header_buffer_size 4k;
client_max_body_size 512k;
large_client_header_buffers 2 8k;
proxy_connect_timeout 5s;
proxy_send_timeout 120s;
proxy_read_timeout 120s;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_next_upstream http_502 http_504 http_404 error timeout invalid_header;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 4;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_vary on;
gzip_disable "MSIE [1-6].";
server
{
listen 8080;
server_name xxx.xxx.xx;
charset utf-8;
access_log /app/esop/nginx/logs/access.log main;
error_log /app/esop/nginx/logs/error.log error;
location /{
root html;
index index.html index.htm;
autoindex on;
expires 30d;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.html?s=$1 last;
break;
}
access_log off;
}
location ^~ /myapp/ {
proxy_pass http://xx.xxx.xx.xx:9911; # 代理的是我自己主机的应用
}
location ^~ /a/ {
proxy_pass http://xx.xxx.xxx.xx:1142/; # 代理应用a
}
location ^~ /a-uri/ {
proxy_pass http://xx.xxx.xx:1142; # 代理应用a下的其他url请求
}
location ^~ /b/ {
proxy_pass http://xx.xxx.xx:6280; # 代理应用b
}
}
}
如上配置,代理 应用a ,使用IE11进行访问时,经常会出现空白页面,400 Bad Request等情况. 发现有个POST请求时间需要很长时间。
我从nginx的access.log中查看该请求所用的时间只有 1.06秒。和正在等待所用的时间相同。但是正在发送就用了9.53秒,我不知道这个时间对应的是哪个阶段。
还有一个问题是,我想配置静态资源的缓存,但是因为代理多个应用,我不知道该怎么配。
最后想问一下这份配置还有优化的空间吗?麻烦指导一下。多谢!!