我有兩個wordpress實例,每個都作爲一個docker容器運行。我想通過單個nginx服務器前端/代理這兩個wordpress實例。如何使用nginx前端運行兩個docker容器的兩個WordPress站點。
以下是我的nginx配置文件。
upstream docker-site1 {
server site1_site;
}
upstream docker-site2 {
server site2_site;
}
server {
listen 80;
server_name myserver.domain.com;
proxy_set_header Host "myserver.domain.com"; # required for Docker client sake
proxy_set_header X-Real-IP $remote_addr; #pass on real client IP
client_max_body_size 0; # disable any limits to avoid HTTP 413 for large image uploads
# required to avoid HTTP 411: see issue #1486 (https://github.com/dotcloud/docker/issues/1486)
chunked_transfer_encoding on;
location /site2 {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/pass/.site1_htpasswd;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_pass http://docker-site2/;
}
location/{
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/pass/.site1_htpasswd;
proxy_set_header Host $http_host;
add_header HTTP_HOST $http_host;
proxy_pass http://docker-site1;
proxy_http_version 1.1;
}
}
此配置是否會導致問題?什麼是錯誤? – Josh
這不是碼頭問題。只是nginx配置... –
即時使用myserver.domain.com/site2時無法訪問site2 –