nginx首页静态化方案
if ( $host ~* (.*)\.(.*)\.(.*)) { set $domain $1; }location =/{rewrite (.*) /html/$domain.html last;}# location =/ {# index index.html index.htm;# if (!-f $request_filename){# rewrite (.*) /template.action;# }# }#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;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; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; #add www.frady.infoupstream mybalance { ip_hash; server 192.168.1.109:8080; server 192.168.1.109:28080; }server { listen 80; server_name *.frady.info ; set $htdocs D:/java/tomcat6/webapps/ROOT/;#此处定义了htdocs root $htdocs; charset utf-8;rewrite ^/products/([0-9]+)\.html$ /showWare.action?ware.wareId=$1 last; location ~^/(WEB-INF)/{ deny all; }location ~ .*.(gif|jpg|jpeg|png|bmp|swf|css|js|html)$ { expires 30d; }location /zanwork/(shopUpload|upload) { proxy_pass http://mybalance; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location ~*.(jsp|do|action)$ { index index.jsp; proxy_pass http://mybalance; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }if ( $host ~* (.*)\.(.*)\.(.*)) { set $domain $1; }location =/{rewrite (.*) /html/$domain.html last;}# location =/ {# index index.html index.htm;# if (!-f $request_filename){# rewrite (.*) /template.action;# }# }}}if ( $host ~* (.*)\.(.*)\.(.*)) { set $domain $1; #设置域名变量,以提供转发使用}location =/{set $zanHtmlFile $htdocs/htmlpage/indexHtml/$domain/index.html;#设置静态文件的位置if (-f $zanHtmlFile){#如果存在静态文件,则跳转到静态文件rewrite / /htmlpage/indexHtml/$domain/index.html last;}if (!-f $zanHtmlFile){#如果不存在静态文件,则跳转到动态地址rewrite / /template4.action last;}}