2

我在 Nginx 中定义了 3 个服务器(用于提供静态内容和作为 tomcat 的代理):

一种处理非加工请求:

server {
   listen 443 default_server;
   return 444;
}

一个用于网络应用 A :

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;
    }
}

一个用于网络应用 B:

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 指的是

"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 回答