Py学习  »  NGINX

如何在nginx中配置子域以指向同一tomcat主机中的specefic html文件

user3600935 • 4 年前 • 279 次点击  

我在tomcat上有一个网站,如www.mysite.com:2121和nginx point(作为代理),如下所示:

mysite.com=>www.mysite.com:2121

www.mysite.com=>www.mysite.com:2121

我想创建一个子域,如ui.mysite.com,指向mysite.com:8080/index_ui.html,如下所示:

ui.mysite.com=>mysite.com:8080/index_ui.html

我在nginx.conf中尝试:

  server {
    listen          80;
    server_name     mysite.com www.mysite.com; 

    location / {
        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 htt://www.mysite.com:2121;
    }
  }
server {
    listen          80;
    server_name     ui.mysite.com ; 
    location / {
        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 htt://www.mysite.com:2121/index_ui.html;
    }
  }

此代码仅适用于HTML,不适用于CSS和JS,因为这些文件位于同一主机中,浏览器在其中查找它们

ui.mysite.com/css(诺基亚)

而不是

mysite.com/css(确定)

我也使用此配置,这意味着重定向所有exept index_ui.html:

rewrite ^(?!^(/index_ui.html)$)/.*$htt://www.xrdini.com/$1 permanent;

这项工作更好,但在不好,因为它不利于搜索引擎优化,它使用户重定向到 mysite.com/index_ui.html 不是 ui.mysite.com/index_ui.html

如何配置Nginx和/或Tomcat?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52013
 
279 次点击  
文章 [ 1 ]  |  最新文章 4 年前
sktan
Reply   •   1 楼
sktan    5 年前

将默认规则覆盖为仅服务器index_ui.html,则需要为根目录设置特定规则,并使用默认规则将代理还原为正常:

server {
    listen          80;
    server_name     ui.mysite.com ;

    # Location block for specifically URL /
    location = / {
        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 htt://www.mysite.com:2121/index_ui.html;
    }
    # Location block for all other URLs
    location / {
        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 htt://www.mysite.com:2121;
    }
}