2

Nginxで定義された3つのサーバーがあります(静的コンテンツの提供とTomcatのプロキシとして使用されます):

一致しないリクエストを処理する 1 つ:

server {
   listen 443 default_server;
   return 444;
}

Web アプリ A 用の 1 つ:

server {
    listen   443;

    server_name webAppA;
    ssl on;
    ssl_certificate /etc/nginx/ssl/webAppA/server.crt;
    ssl_certificate_key /etc/nginx/ssl/webAppA/server.key;

    index index.html;
    root /var/www/webAppA/;

    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    location / {
      try_files $uri $uri/ /index.html;
    }

    location /ws/ {
        add_header Cache-Control no-cache;
        proxy_pass        http://localhost:8080/webAppA/ws/;
        proxy_set_header  X-Real-IP  $remote_addr;
    }
}

Web アプリ B 用の 1 つ:

server {

    listen   443;
    ssl on;
    ssl_certificate /etc/nginx/ssl/webAppB/server.crt;
    ssl_certificate_key /etc/nginx/ssl/webAppB/server.key;
    server_name webAppB

    index index.html;
    root /var/www/webAppB/;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    location /ws/ {
            add_header Cache-Control no-cache;
            proxy_pass        http://localhost:8080/webAppB/ws/;
            proxy_set_header  X-Real-IP  $remote_addr;
    }
    location / {
      #auth_basic            "Restricted";
      #auth_basic_user_file  htpasswd;
      try_files $uri $uri/ /index.html;
    }
}

私は両方のアプリにアクセスしようとしています:

https://server_ip/webAppA
https://server_ip/webAppB

ただし、デフォルト サーバーは常に選択されます。TSL SNI サポートを有効にしています。

サーバー名を /etc/hosts に追加しようとしましたが、何も変わりません。

何か考えはありますか?

どうもありがとう :)

4

1 に答える 1

0

確立された解決策は、server_nameが参照するため、1つのサーバーを作成することでした

"https://server_ip" 

「wabAppA」や「webAppB」ではありません。

server {
   listen 443;

   ssl on;
   ssl_certificate /etc/nginx/ssl/server.crt;
   ssl_certificate_key /etc/nginx/ssl/server.key;

   root /var/www/;

   location /webAppA/ {
     try_files $uri $uri/ /webAppA/index.html;
   }

   location /webAppB/ {
     try_files $uri $uri/ /webAppB/index.html;
   }

   location /webAppA/ws/ {
     add_header Cache-Control no-cache;
     proxy_pass        http://localhost:8080/webAppA/ws/;
     proxy_set_header  X-Real-IP  $remote_addr;
   }

   location /webAppB/ws/ {
     add_header Cache-Control no-cache;
     proxy_pass        http://localhost:8080/webAppB/ws/;
     proxy_set_header  X-Real-IP  $remote_addr;
   }
}

思ったほど柔軟ではありませんが、機能します。

于 2014-07-08T09:47:47.877 に答える