nginx.conf
动静分离rewrite新域名跨越问题
rewrite ^/ http://staticwww.dachuizichan.com$uri permanent;
add_header Access-Control-Allow-Origin *;
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Access-Control-Allow-Origin, x-requested-with, content-type';
return 200;
}
user nginx;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include 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 logs/access.log main;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2; 1-10,数字越大压缩的越好,时间也越长
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/
x-httpd-php image/jpeg image/gif image/png;
gzip_vary off; 跟Squid等缓存服务有关,on的话会在Header里增加"Vary: Accept-Encoding"
proxy_temp_path /tmp/temp_dir; #缓存目录
proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g;
server {
listen 81;
server_name localhost;
rewrite ^/ http://$host:8081/3m/index.do last;
}
server {
listen 8081;
server_name localhost;
root /usr/local/tomcat/webapps;
location ~ (\.jsp|\.do|imageServlet)$ {
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
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 10m; #允许客户端请求的最大单文件字节数
client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数
proxy_connect_timeout 90; #nginx跟后端服务器连接超时时间(代理连接超时)
proxy_read_timeout 90; #连接成功后,后端服务器响应时间(代理接收超时)
proxy_buffer_size 4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers 6 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
proxy_busy_buffers_size 64k;#高负荷下缓冲大小(proxy_buffers*2)
proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传
}
location ~ .*\.(html|js|css|gif|jpg|png|bmp|swf|ico|txt)?$ {
proxy_cache cache_one; # 设置缓存共享内存区块,也就是keys_zone名称。
proxy_cache_valid 200 302 1h;
expires 1d;
root /usr/local/nginx/aaa/; 文件目录
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}