# NGinX

## Revert Proxy

#### สร้าง docker image ของ nginx

```docker
#Dockerfile
FROM nginx:latest
```

#### ไฟล์ docker compose

```batch
#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

```batch
#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/;
        }
}
```

{% hint style="info" %}
proxy\_pass <http://weblinkauthen:5001/> \
&#x20;   weblinkauthen : เป็นเหมือน alias ที่รู้จักกันภายใน network เดียวกันจะสามารถใช้แทน IP ได้\
[<mark style="color:blue;">ดูการ config ได้ ที่นี่</mark>](https://kidkung.gitbook.io/node-js/docker/problem-and-solution#run-docker-script-containner-ip)
{% endhint %}

{% embed url="<https://dev.to/danielkun/nginx-everything-about-proxypass-2ona>" %}
วิธีการ config proxy\_pass
{% endembed %}
