#user nobody; worker_processes 2; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 10240; #默认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"'; log_format main '"$remote_addr" "$http_x_real_ip" "[$time_local]" ' '"$status" "$request_time" "$upstream_response_time" "$body_bytes_sent" "$upstream_addr" "$cookie_jsessionid" "$request" ' '"$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" ' '"$upstream_cache_status" '; access_log logs/mes-access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; lua_package_path "$prefix/?.luac;$prefix/?.lua;;"; #gzip on; gzip on; # enable gzip gzip_http_version 1.1; # turn on gzip for http 1.1 and above gzip_disable "msie6"; # IE 6 had issues with gzip gzip_comp_level 8; # inc compresion level, and CPU usage gzip_min_length 100; # minimal weight to gzip file gzip_proxied any; # enable gzip for proxied requests (e.g. CDN) gzip_buffers 16 8k; # compression buffers (if we exceed this value, disk will be used instead of RAM) gzip_vary on; # add header Vary Accept-Encoding (more on that in Caching section) # define files which should be compressed gzip_types text/plain; gzip_types text/css; gzip_types application/javascript; gzip_types application/json; gzip_types application/vnd.ms-fontobject; gzip_types application/x-font-ttf; gzip_types font/opentype; gzip_types image/svg+xml; gzip_types image/x-icon; #代表了临时文件夹 proxy_temp_path d:/nginx-temp; #设置了缓存目录 proxy_cache_path d:/nginx-cache #levels代表采用1:2也就是两级目录的形式保存缓存文件(静态资源css,js),同时文件名进行了md5编码 #keys_zone 定义缓存的名称及内存的使用,名称为babytun-cache,在内存中开始100m交换空间 #inactive=7d 如果某个缓存文件超过7天没有被访问,则删除,如果7天内访问过,则延续7天 #max_size=20g 代表设置文件夹最大不能超过20g,超过后会自动将访问频率(命中率)最低的缓存文件删除 proxy_cache_path d:/nginx-cache levels=1:2 keys_zone=babytun-cache:100m inactive=7d max_size=20g; upstream uma-pct-web { ip_hash; #sticky; server 127.0.0.1:8080; #server 127.0.0.1:8331; # server 127.0.0.1:8332 down; # server 127.0.0.1:8333 down; # server 127.0.0.1:8080; } upstream mestar-rs-7.0 { ip_hash; #sticky; server 127.0.0.1:8340; # server 127.0.0.1:8341; } server { listen 80; server_name 127.0.0.1; client_max_body_size 0; #charset koi8-r; access_log logs/mes-access.log main; #静态资源缓存 #利用正则表达式匹配url,匹配成功则执行内部逻辑 #~* 不区分大小写,~ 区分大小写 location ~* \.(gif|jpg|png|js|css)(.*) { proxy_pass http://uma-pct-web; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cache babytun-cache; #如果静态资源响应状态码为200(成功)302 (暂定性重定向)时,缓存文件有效期一天 这个缓存有效期优先级高 proxy_cache_valid 200 302 24h; #301(永久性重定向) 缓存保存5天 proxy_cache_valid 301 5d; proxy_cache_valid 504 10s; proxy_cache_valid any 1m; #浏览器的缓存时间 expires 7d; add_header msg "nginx cache ok"; } location / { root html; index index.html index.htm; proxy_connect_timeout 90; proxy_send_timeout 300; proxy_read_timeout 300; send_timeout 300; #增加内容 proxy_set_header X-Real-IP $remote_addr;#将header中设置为真实ip,而不是代理Ip proxy_set_header Host $host; #针对header中的host进行转发 proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_pass http://uma-pct-web; #health_check uri=/sessionDuplicate.jsp interval=10 fails=3 passes=2; } location /mestar-rs-7.0 { root html; index index.html index.htm; #增加内容 proxy_set_header X-Real-IP $remote_addr;#将header中设置为真实ip,而不是代理Ip proxy_set_header Host $host; #针对header中的host进行转发 proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://mestar-rs-7.0; #health_check uri=/sessionDuplicate.jsp interval=10 fails=3 passes=2; } location /lua { default_type text/plain; #content_by_lua 'ngx.say("hello, lua")'; cookie_desktopMenuStyle cookie_JSESSIONID content_by_lua ' if ngx.var.cookie_desktopMenuStyle == nil then ngx.say("cookie user: missing") else ngx.say("cookie user: [", ngx.var.cookie_desktopMenuStyle, "]") end '; } #error_page 404 /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_pass http://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 { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }