直接上代码!
server { # 监听端口 listen 521; # 监听服务名,也可以是ip或域名 server_name default_server; # 禁用一个header头里面的userId为10。 if ($http_userId ~ '10') { return 403 "Error userId forbidden."; } # 拦截指定页面,~* 是不区分大小写,~ 区分大小写,拦截后重写地址,参数会一起传入重写地址,重写地址可以是另一个页面,也可以是服务接口地址 if ($request_uri ~* "tyg.html") { rewrite ^/ http://tyg.com/templates/tygController; } # 访问服务名的时候,重写地址 location = / { rewrite ^/ http://tyg.com/component/home/home.html; } # 请求地址 location / { proxy_pass http://tyg.com; } # 静态文件 location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css|woff|ttf|js|swf|svga|json)$ { root E:\pageHtml; index login.html; } } 注意点:if和(之间要有空格,语句后面要跟分号,切记! --------------------- 原文:https://blog.csdn.net/qq_26365837/article/details/90260098