NGINX根据域名配置反向代理

NuoYI 2021年02月08日 242次浏览
upstream demo01 {
	server 127.0.0.1:8001;
}
upstream demo02 {
	server 127.0.0.1:8002;
}
upstream demo03 {
	server 127.0.0.1:8003;
}
server {
	listen 80;
	listen [::]:80;
	server_name  ~^demo(?<num>.*).example.com$;
	client_max_body_size 1024m;

	location / {
		#设置默认编号
		if ( $num == '' ) {
			set $num = '01';
		}
		proxy_pass       $scheme://demo$num;
		proxy_redirect   off;
		proxy_set_header Host $host;
		proxy_set_header X-Forwarded-Proto $scheme;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	}
}