Nginx intercept a specified HTML

Look it over! Directly on the code!

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;
	}
}

Note the point: if and (there must be a space between the statement back to keep semicolon, remember!

Guess you like

Origin blog.csdn.net/qq_26365837/article/details/90260098