1. 程式人生 > >Docker中nginx根據埠代理

Docker中nginx根據埠代理

一、新建一個.conf檔案,寫入內容:

upstream ma{
server 172.17.0.1:8080;
}
upstream sys{
	server 172.17.0.1:8081;
}

server {
	listen       8080;
	server_name  47.xxx.71.235;
	access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log;

	location / {
		proxy_set_header Host $host;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_pass http://ma;
	}
}

server {
	listen       8081;
	server_name  47.xxx.71.235;
	access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log;

	location / {
		proxy_set_header Host $host;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_pass http://sys;
	}
}

二、將.conf檔案放入到/etc/nginx/conf.d/下