私のサーバにはwebsite1.com
とwebsite2.com
という2つのドメインがあります。私は、次の書き換えルールをやろうとしているホストに依存するnginxリダイレクト
:
http://website1.com/ --> /website1/ (static)
http://website2.com/ --> /website2/ (static)
http://website1.com/app/ --> http://localhost:8080/web-app/web1/
http://website2.com/app/ --> http://localhost:8080/web-app/web2/
ユーザーは、nginxのか、URLに応じて、アプリケーション・サーバによって提供される静的なWebサイトにリダイレクトされます。
は、ここで私はこれまで試したものです:
location/{
root html;
index index.html index.htm;
if ($http_host = website1.com) {
rewrite/ /website1/index.html break;
rewrite (.*) /website1/$1;
}
if ($http_host = website2.com) {
#same logic
}
}
location /app/ {
proxy_pass http://localhost:8080/web-app/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
if ($http_host = website1.com) {
rewrite /app/(.*) /$1 break;
rewrite /app /index.html;
}
if ($http_host = website2.com) {
#same logic
}
}
静的な部分が正常に動作するようだが、リダイレクトWebアプリケーションの一部は、要求されたファイルが何であるかに関係なく、index.htmlを果たすようです。
WEBSITE1とウェブサイト2は独立していないでくださいサーバーブロック? – MatTheWhale
彼らは?これは今までのnginxとの最初のエンコーダーです。 –
もしあなたがそうしたなら、それらの 'if($ http_host ==)'ブロックをすべて持つ必要はありません。彼らは問題の原因になる可能性があります – MatTheWhale