本文共 3711 字,大约阅读时间需要 12 分钟。
1,nginx.conf [root@datanode03 conf]# cat nginx.conf user nobody nobody; worker_processes 4; error_log logs/error.log crit; pid logs/nginx.pid; worker_rlimit_nofile 65535; events { use epoll; worker_connections 65535; } http { include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 128k; client_max_body_size 300m; 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; #tcp_nopush on; keepalive_timeout 65; include conf.d/gzip.conf; include conf.d/proxy.conf; include conf.d/server_group3.conf; include conf.d/upstream_group3.conf; } 2,server_group3.conf server { listen 80; server_name www.b2b.cn; index index.html index.htm,index.aspx; root /app/$host; location ~ .*\.(css|jpg|png|gif|bmp|js|mp3|mp4|wmv|rm|swf|mpeg|wma|flv|htm|html)$ { expires 1d; proxy_store /app/$host${uri}; proxy_store_access user:rw group:rw all:rw; #proxy_temp_path /app/cache; if ( !-e $request_filename) { proxy_pass http://www_b2b_cn_backend; } } location ~ .*\.(php|jsp|aspx|ashx|cgi)?$ { proxy_pass http://www_b2b_cn_backend; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; } location ~ / { expires 1d; proxy_pass http://www_b2b_cn_backend; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; } } 3,gzip.conf [root@datanode03 conf.d]# cat gzip.conf gzip on; gzip_min_length 1k; gzip_buffers 4 32k; gzip_http_version 1.1; gzip_comp_level 4; gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/javascript; gzip_vary on; gzip_disable "MSIE [1-6]\."; 4,proxy.conf [root@datanode03 conf.d]# cat proxy.conf proxy_set_header X-Forwarded-For $remote_addr; #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #proxy_set_header X-Forwarded-For $http_x_forwarded_for; #proxy_set_header REMOTE_ADDR $remote_addr; #proxy_set_header RealIP $remote_addr; #proxy_set_header X-RealIP $remote_addr; proxy_set_header Host $host; proxy_set_header Accept-Encoding ''; proxy_headers_hash_max_size 51200; proxy_headers_hash_bucket_size 6400; client_body_buffer_size 512k; proxy_connect_timeout 15s; proxy_read_timeout 1m; proxy_send_timeout 1m; proxy_buffer_size 32k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 1024m; proxy_ignore_client_abort on; proxy_next_upstream error timeout invalid_header http_503 http_500 http_404 http_502 http_504; #proxy_temp_path /app/proxy_temp_dir; #proxy_cache_path /app/proxy_cache_dir levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=5g; #proxy_cache cache_one; #proxy_cache_valid 200 304 12h; #proxy_cache_valid 301 1d; #proxy_cache_valid any 1m; #proxy_cache_key $host$uri$is_args$args; 5,upstream_group3.conf [root@datanode03 conf.d]# cat upstream_group3.conf upstream www_b2b_cn_backend { server 117.79.149.76; } 6,缓存目录/app [root@datanode03 conf.d]# cd /app/ [root@datanode03 app]# ls www.b2b.cn [root@datanode03 app]# cd www.b2b.cn/ [root@datanode03 www.b2b.cn]# ls flashfile huodong top [root@datanode03 www.b2b.cn]# pwd /app/www.b2b.cn [root@datanode03 www.b2b.cn]# cd top/ [root@datanode03 top]# ls 254150.htm 5558.htm 已缓存文件 7,总结: 开始配置proxy_store /app/$host${uri}时在/app目录下总是无法生成$host目录www.b2b.cn,经检查error.log发现/usr/local/nginx/proxy_temp目录没有权限,删了proxy_temp目录,重新启动killall -s HUP nginx后还不行,后来发现应该将下面配置文件放在最后面:(开始时在server下) location ~ / { expires 1d; proxy_pass http://www_b2b_cn_backend; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr;
转载于:https://blog.51cto.com/6727761/1151662