INAUGURATE-Ryong / docker-nginx-vhost

0 stars 0 forks source link

NGINX-PATH-ROUTING #7

Open INAUGURATE-Ryong opened 8 months ago

INAUGURATE-Ryong commented 8 months ago

ref https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass https://docs.nginx.com/nginx/admin-guide/web-server/web-server/

INAUGURATE-Ryong commented 8 months ago

build & run

$ docker build -t lb:1 -f lb/Dockerfile lb/
$ docker build -t serv-a:1 -f serv-a/Dockerfile serv-a/
$ docker build -t serv-b:1 -f serv-b/Dockerfile serv-b/

$ docker network create r-net
$ docker run -d --name serv-a --network r-net serv-a:1
$ docker run -d --name serv-b --network r-net serv-b:1
$ docker run -d -p 8001:80 --name lb --network r-net lb:1
INAUGURATE-Ryong commented 8 months ago

config/default.conf 파일 수정

upstream serv {
    server serv-a:80;
}

upstream blogs{
        server serv-b:80;
}
server {
    listen 80;

    location /
    {
        proxy_pass http://serv;
    }

    location /blogs
    {
        proxy_pass http://blogs/;   <- 뒤에 /  추가해야함
    }
}
INAUGURATE-Ryong commented 8 months ago

curl

$ curl http://localhost:8001
<h1>A</h1>

$ curl http://localhost:8001/blogs
<h1>B</h1>