通过DNS名称访问位于单个服务器中的多个网站

时间:2019-10-14 07:26:21

标签: java apache tomcat nginx

我已经在apache / tomcat中部署了两个应用程序,它们正在按以下方式运行(http://xx.xx.xx.xx:8080/castag/http://xx.xx.xx.xx:8080/filltag/),并且可以正常访问

但我的要求是

http://xx.xx.xx.xx:8080/castag/ ------> casstag.abc.com

http://xx.xx.xx.xx:8080/filltag/ -----> filltag.abc.com

为此,

1。在dns服务器中添加两个主机A记录

2。我已经安装了nginx服务器,并在apache tomcat服务器中的server.xml中进行了一些更改

   <Context path="/casstag" docBase="/opt/apache-tomcat-6.0.45/webapps/casstag" debug="0"
                reloadable="true" cachingAllowed="false"
                allowLinking="true" />
   <Context path="/filltag" docBase="/opt/apache-tomcat-6.0.45/webapps/filltag" debug="0"
                reloadable="true" cachingAllowed="false"
                allowLinking="true" />

  1. 在nginx / etc / nginx / sites-enabled /
  2. 中创建两个conf文件(castag.conf和filltag.conf)。
server {
    listen xx.xx.xx.xx:80;
    server_name def.abc.com ;

    root /opt/apache-tomcat-6.0.45/webapps;

        location / {
                deny all;
        }

    location /castag/ {
        index index.jsp;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://xx.xx.xx.xx:8080/castag/; 
        proxy_redirect  http://xx.xx.xx.xx:8080/castag/  http://casstag.abc.com ;

        proxy_buffering off;
        proxy_store     off;

        proxy_connect_timeout 120;
        proxy_send_timeout    120;
        proxy_read_timeout    120;

    }
}

server {

    listen xx.xx.xx.xx:80;
    server_name def.abc.com ;

    root /opt/apache-tomcat-6.0.45/webapps;

        location / {
                deny all;
        }
 location /filltag/ {
        index index.jsp;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://xx.xx.xx.xx:8080/filltag/; 
        proxy_redirect  http://xx.xx.xx.xx:8080/filltag/  filltag.abc.com ;

        proxy_buffering off;
        proxy_store     off;

        proxy_connect_timeout 120;
        proxy_send_timeout    120;
        proxy_read_timeout    120;
    }
}



1 个答案:

答案 0 :(得分:0)

根据nginx.org docs,您必须为每个服务器设置server_name。然后,您应该创建多个具有不同根目录的服务器。

相关问题