一、使用场景
有一台服务器,现在需要部署两个tomcat。要求访问网站的地址不要出现端口号。
80端口只有一个,两个tomcat会占用两个端口
二、解决方案
- url域名转发,这个在域名后台管理网站上可以配置,要花钱
- 多启动一个tomcat占用80端口(https的用443),这个tomcat专门管转发,在tomcat的ROOT目录下创建文件夹aaa,然后建立一个网页index.html,访问 http://[ip地址或域名]:[端口号]/aaa 就可以跳转至8080端口下网站
<script>
location.href="http://[ip地址或域名]:[端口号]";
//location.href="http://www.abc.com:8080";
</script>
3.nginx反向代理
配置nginx的config(编译安装路径/conf/nginx.conf):
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#=========================================
#添加这个begin
#=========================================
location /aaa{
root html;
index index.html index.htm;
proxy_pass http://127.0.0.1:8080;
}
#=========================================
#添加这个end
#=========================================
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}