NGinX

ซอฟต์แวร์โอเพนซอร์สสำหรับ Web service แบบ Revert Proxy, Load Balance, Streaming และ Other

Revert Proxy

สร้าง docker image ของ nginx

#Dockerfile
FROM nginx:latest

ไฟล์ docker compose

#docker-compose.yml
version: '3.4'
services:
    nginx:
        image: nginx
        container_name: nginx
        networks:
            - load-balancer
        volumes:
            - ${PWD}/default.conf:/etc/nginx/conf.d/default.conf:ro
        build:
            context: .
            dockerfile: ./Dockerfile
        ports:
            - "8888:80"
networks:
  load-balancer:
    driver: bridge
    name: server_load_balancer

ไฟล์ config ตัว nginx เพื่อทำ revert proxy

#default.conf
server {
        location /authenendpoint/ {
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_pass http://weblinkauthen:5001/;
        }
}

proxy_pass http://weblinkauthen:5001/ weblinkauthen : เป็นเหมือน alias ที่รู้จักกันภายใน network เดียวกันจะสามารถใช้แทน IP ได้ ดูการ config ได้ ที่นี่

วิธีการ config proxy_pass

Last updated