
假設我有一個帶有 Nginx 的 Droplet,並設定了到特定 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
我設定了單一 docker 並在子資料夾中新增了兩個 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/;
}
}
我如何在 docker 容器中設定 nginx conf 檔案才能 http://domain1.com和http://domain2.com
我發現大多數答案都是為每個網站使用單獨的 docker 容器。但由於某種原因我需要使用單一容器。
答案1
如果您希望每個網站回應不同的主機名,那麼您需要server
在後端為每個主機名稱使用單獨的區塊,就像您在其他 nginx 伺服器上所做的那樣。