단일 도커에 WordPress 2개 및 역방향 프록시 Nginx로 액세스

단일 도커에 WordPress 2개 및 역방향 프록시 Nginx로 액세스

Nginx가 포함된 드롭릿이 있고 특정 Docker 컨테이너 하위 폴더에 대한 역방향 프록시를 설정했다고 가정해 보겠습니다. 아래는 nginx에 대한 역방향 프록시 설정입니다.

프론트엔드 Nginx

#For Domain 1
server {
    listen   80;
    server_name  domain1.com;

    location / {
        proxy_pass http://127.0.0.1:7000/domain1/;
        proxy_redirect     off;
        proxy_set_header   Host $host;
    }
}

#For Domain 2
server {
    listen   80;
    server_name  domain2.com;

    location / {
        proxy_pass http://127.0.0.1:7000/domain2/;
        proxy_redirect     off;
        proxy_set_header   Host $host;
    }
}

백엔드 Nginx

단일 도커를 설정하고 하위 폴더에 두 개의 WordPress 웹 사이트를 추가합니다. 아래와 같이

/var/www /root directory
/var/www/domain1 //domain 1 website 
/var/www/domain2 //domain 2 website 

docker nginx conf.d 파일 설정은 아래와 같습니다.

server {
    listen 80;
    index index.php index.html;
    root /var/www;
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
    
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    #domain1 setup <----------- my issues might be here 
    location /domain1 {
            #try_files $uri $uri/  /domain1/index.php?$args;
        root /var/www/;
    }

    #domain2 setup <----------- my issues might be here 
    location /domain2 {
            #try_files $uri $uri/  /domain2/index.php?$args;
        root /var/www/;
    }

}

nginx conf 파일이 가능하도록 docker 컨테이너에 어떻게 설정할 수 있습니까? http://domain1.com그리고http://domain2.com

대부분의 답변은 각 사이트마다 별도의 도커 컨테이너를 사용하는 것으로 나타났습니다. 하지만 어떤 이유로 단일 컨테이너를 사용해야 합니다.

답변1

각 사이트가 서로 다른 호스트 이름에 응답하도록 하려면 server다른 nginx 서버에서 이미 했던 것처럼 백엔드의 각 호스트 이름에 대해 별도의 블록을 사용해야 합니다.

관련 정보