2021年12月4日星期六

nginx reverse proxy

docker run --name nginx -p 80:80 -v /home/$(whoami)/data/nginx/html:/usr/share/nginx/html:ro -v /home/$(whoami)/data/nginx/conf:/etc/nginx nginx 

ref:https://github.com/dunwu/nginx-tutorial

http {

upstream product_server{
server www.helloworld.com:8081;
}

upstream admin_server{
server www.helloworld.com:8082;
}

upstream finance_server{
server www.helloworld.com:8083;
}

server {
#此处省略一些基本配置
#默认指向product的server
  
  // for hide port 
  server_name_in_redirect off;
  proxy_set_header Host $host:$server_port;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

location / {
proxy_pass http://product_server;
}

location /product/{
proxy_pass http://product_server;
}

location /admin/ {
proxy_pass http://admin_server;
}

location /finance/ {
proxy_pass http://finance_server;
}


# load balance 
upstream backend { ip_hash; server 192.168.1.106:80; server 192.168.1.107:80; }

没有评论: