nginx的妙用

网关验证使用

http://192.168.68.200/api/?token=success

server {
	listen 80;
	listen  [::]:80;
	server_name 192.168.68.200;
	# 首页
	index index.html;
	location / {
		root /usr/share/nginx/html;
		index index.html index.htm;
	}
	location /api/ {
		auth_request /auth;
		# 鉴权通过后的处理方式
		proxy_pass http://192.168.68.222:8080/success;
	}
	location = /auth {
		# 发送子请求到HTTP服务,验证客户端的凭据,返回响应码
		internal;
		# 设置参数
		set $query '';
		if ($request_uri ~* "[^\?]+\?(.*)$") {
			set $query $1;
		}
		# 验证成功,返回200 OK
		proxy_pass http://192.168.68.222:8080/verify?$query;
		# 发送原始请求
		proxy_pass_request_body off;
		# 清空 Content-Type
		proxy_set_header Content-Type "";
	}
	error_page 404 /404.html;
		location = /40x.html {
	}
	error_page 500 502 503 504 /50x.html;
		location = /50x.html {
	}
}

非常适合学习的nginx配置

非常适合学习的nginx配置链接

posted @ 2023-05-14 20:42  尐海爸爸  阅读(9)  评论(0编辑  收藏  举报