user root;
worker_processes 8;
#error_loglogs/error.log;
#error_loglogs/error.log notice;
#error_loglogs/error.log info;
#pidlogs/nginx.pid;
events {
worker_connections 102400;
}
http {
include mime.types;
default_typeapplication/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;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
##缓存cache参数配置##
proxy_connect_timeout 300;
proxy_read_timeout 300;
proxy_send_timeout 300;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
#缓存到nginx的本地目录
#proxy_temp_path/usr/local/nginx/cache;
#proxy_cache_path /usr/local/nginx/cache levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=3g;
#压缩配置#
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_comp_level 2;
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;
#具体的服务器地址及端口号,该处可以配置集群实现负载均衡,cluster为服务器集群名
upstream cluster{
server 10.201.8.97:8081;
server 10.201.8.98:8081;
}
proxy_cache_path /usr/local/nginx/cache levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=3g;
server {
listen 8081;
server_name 10.201.8.99;
#rewrite ^(.*)$ https://$host$1 permanent; #这里是http跳转https
#charset koi8-r;
#access_loglogs/host.access.log main;
#缓存相应的文件(静态文件)
location / {
proxy_cache_methods GET HEAD POST;
proxy_pass http://cluster;
proxy_redirect off;
proxy_set_header Host $host;
proxy_cache cache_one;
proxy_cache_valid 200 302 1h;
proxy_cache_valid 301 1d;
proxy_cache_valid any 1m;
proxy_cache_key $host$uri$is_args$args$request_uri;
add_header Nginx-Cache "$upstream_cache_status";
proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header X-real-ip $remote_addr;
add_header backendIP $upstream_addr;
add_header backendCode $upstream_status;
expires 30d;
}
#动态请求代理给相应服务器
#error_page404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_passhttp://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# denyall;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen8000;
# listensomename:8080;
# server_namesomename alias another.alias;
# location / {
# roothtml;
# indexindex.html index.htm;
# }
#}
}