
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
単一のDockerをセットアップし、サブフォルダーに2つのWordPress Webサイトを追加します。以下のように
/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
ほとんどの回答では、サイトごとに個別の Docker コンテナを使用していることがわかりました。しかし、何らかの理由で単一のコンテナを使用する必要があります。
答え1
server
各サイトが異なるホスト名に応答するようにしたい場合は、他の nginx サーバーで既に行ったように、バックエンドでホスト名ごとに個別のブロックを使用する必要があります。