实践笔记_J2EE_Server_Tomcat_tomcat域名绑定_1_单域名绑定
Tomcat域名绑定(1)单域名绑定
1. 测试环境说明
名称 | 版本 | 备注 |
操作系统 | win10 教育版1803 | |
web服务器 | tomcat7.0 | |
浏览器 | Google Chrome71.0.3578.98 | |
2.简单方式一:操作步骤
预期的结果是: 通过www.slm.cn 直接访问到tomcat中的项目的首页
2.1 实现访问时用 域名 代替 localhost或ip
2.1.1 修改host文件
A. 打开运行 输入 C:\WINDOWS\system32\drivers\etc
B.记事本打开host文件,添加域名映射
这里我用的是一个测试过还在外租售的域名 www.slm.cn (PS:不是我的)
#代表注释
以下面的方式映射:
127.0.0.1 www.slm.cn
2.1.2 保存host文件 访问
ps:
到目前为止已经完成了ip和域名的绑定,这时候我们通过www.slm.cn就能访问到本机了.
以tomcat为例访问项目, 现在的访问地址就是: http://www.slm.cn:8080/项目名
但是这样端口和项目名还是暴露了,下面来解决这个问题
2.2 隐藏8080端口
这个很简单,就是将tomcat响应端口从8080端口修改为80端口
2.2.1 操作步骤如下:
A.打开tomcat server.xml文件,找到下行代码:
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />
B.将上述代码中的 8080 修改为 80 .如下:
<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />
C.保存 server.xml文件
这时访问地址中的端口就隐藏成功了.访问地址就变成了: http://www.slm.cn/项目名
但是项目名还是存在,所以接下来我们还要隐藏项目名.
2.3 隐藏项目名
同样是修改server.xml文件.操作如下
2.3.1 操作步骤:
A.打开server.xml,找到 host节点
B.将一个host节点中的localhost 全部改为www.slm.cn
并添加子节点:<Context path="" docBase="/项目名/" reloadable="true" />
比如我的项目名叫WEBTEST 所以修改后就是:
<Host name="www.slm.com" appBase="webapps"unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context path="" docBase="/WEBTEST/" reloadable="true" ></Context>
</Host>
C.找到
<Engine name="Catalina" defaultHost="localhost">
将defaultHost 的值 localhost 更改为 www.slm.cn 如下:
<Engine name="Catalina" defaultHost="www.slm.cn">
从这里可以看到,它其实是映射关系,所以HOST其实可以有多个,但默认的就只有一个.
这就为后面配置多个项目日共了便利.这里我们只设置单个项目的映射.
2.3.2 完整的示例
以tomcat为服务器,www.slm.cn为访问域名 crm为项目名 ,那么完整修改后的server.xml如下
2.4 保存修改的server.xml文件 重启tomcat
3.测试
3.1 这个时候加端口号的这个访问就访问不到了:
3.2 我们访问域名: http://www.slm.cn 结果如下:
4.其它版本测试
4.1. Tomcat8.5 winX64
4.1.1 server.xml 配置
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--><!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
--><Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
-->
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/> <!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
</GlobalNamingResources> <!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina"> <!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
--> <!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
-->
<Connector connectionTimeout="20000" port="80" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="utf-8"/>
<Engine defaultHost="www.slm.cn" name="Catalina">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm> <Host appBase="webapps" autoDeploy="true" name="www.slm.cn" unpackWARs="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b"
prefix="localhost_access_log" suffix=".txt"/> <Context docBase="/SpringMVCDemo/" path="" reloadable="true" /></Host>
</Engine>
</Service>
</Server>
4.1.2 效果
5.参考文献
5.1 tomcat设置直接通过域名访问项目(不需要接 /项目名)
https://blog.csdn.net/qq_33647275/article/details/52585489
5.2 一个Tomcat下部署两个,甚至多个项目
https://blog.csdn.net/junhou5/article/details/61923837
5.3 同一个Tomcat部署多个项目
https://blog.csdn.net/dreamstar613/article/details/75282962/
5.4 把域名和IP地址绑定后,利用域名+端口号访问自己搭建的网站
https://blog.csdn.net/liuzhongyefirst/article/details/81946686
实践笔记_J2EE_Server_Tomcat_tomcat域名绑定_1_单域名绑定的更多相关文章
- Vue的指令系统、计算属性和表单输入绑定
指令系统 指令 (Directives) 是带有 v- 前缀的特殊特性.指令特性的值预期是单个 JavaScript 表达式 (v-for 是例外情况,稍后我们再讨论).指令的职责是,当表达式的值改变 ...
- Taurus.MVC 微服务框架 入门开发教程:项目部署:2、让Kestrel支持绑定多个域名转发,替代Ngnix使用。
系列目录: 本系列分为项目集成.项目部署.架构演进三个方向,后续会根据情况调整文章目录. 本系列第一篇:Taurus.MVC V3.0.3 微服务开源框架发布:让.NET 架构在大并发的演进过程更简单 ...
- 阿里云Nginx绑定多个域名的方法
nginx绑定多个域名,可通过把多个域名规则写一个配置文件里实现,也可通过分别建立多个域名配置文件实现,一般为了管理方便,建议每个域名建一个文件,有些同类域名也可写在一个总的配置文件里. 一.每个域名 ...
- PHP同一个IP绑定多个域名(六)
原理图 一个ip绑定如何绑定多个域名? 解决方案: A.方案一:端口号来区别不同的站点 1.绑定一个网站 1.1先开发好自己的网站 d:/ApacheProject/myanimal 1.2 配置我们 ...
- nginx绑定多个域名
nginx绑定多个域名涉及到的技术为url rewrite,可以先了解下知识背景再过来学习. 这里以域名:www.sample.com为例 1.在/usr/local/nginx/conf文件夹中创建 ...
- APACHE如何里一个站点绑定多个域名?用ServerAlias
APACHE2如何里一个站点绑定多个域名?用ServerAlias以前很笨,要使多个域名指向同一站点总是这样写: <VirtualHost *:80>ServerAdmin i@kuigg ...
- nginx 多域名配置 (nginx如何绑定多个域名)
nginx绑定多个域名可又把多个域名规则写一个配置文件里,也可又分别建立多个域名配置文件,我一般为了管理方便,每个域名建一个文件,有些同类域名也可又写在一个总的配置文件里. 一.每个域名一个 ...
- Apache 一台主机绑定多个域名及虚拟主机
今天研究了下Apache下如何使用一台主机绑定多个域名且使用80端口.说白了就是在一台主机上运行多个网站,并且网站域名都是使用的80端口. 具体方法如下: 1.进入Apache conf目录,找到ht ...
- CentOS6.5 服务器+apache5.3绑定多个域名+SELinux设置
下面简单的介绍了如何通过设置Apache的http.conf文件,进行多个域名以及其相关的二级域名的绑定(假设我们要绑定的域名是minidx.com和ntt.cc,二级域名是blog.minidx.c ...
随机推荐
- Spring Boot报错 MultipartException The temporary upload...
Spring Boot报错:尤其是在处理Ribbon这类接口调用型的负载均衡组件,常见问题 ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.se ...
- 【Linux】CentOS7下安装JDK详细过程
https://www.cnblogs.com/sxdcgaq8080/p/7492426.html
- LIS ZOJ - 4028
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4028 memset超时 这题竟然是一个差分约束 好吧呢 对于每一个a[i] ...
- 查看Linux的所有线程
查看Linux所有线程有3种方法: ps -T <pid>可以看指定pid的所有线程,SPID就是指线程.或者用ps -eLf top -H,和普通的top命令相比,多了Thread ht ...
- POJ2975 Nim 【博弈论】
DescriptionNim is a 2-player game featuring several piles of stones. Players alternate turns, and on ...
- JavaScript中数据类型判断
做判断前先来了解下 JavaScript 中的基本数据类型 一.七大数据类型 基本类型:存储在栈( stack )中 Number(包括整型和浮点型) String. Boolean. Symbol ...
- @NotNull @NotEmpty @NotBlank区别
@interface NotNull The annotated element must not be {@code null}.Accepts any type.----------------- ...
- 编写高质量的Python代码系列(七)之协作开发
如果多个人要开发同一个Python程序,那就得仔细商量代码的写法了.即使你是一个人开发,也需要理解其他人所写的模块.本节讲解多人协作开发Python程序时所用的标准工具及最佳做法. 第四十九条:为每个 ...
- Java基础知识拾遗(三)
集合框架 SortedSet接口,声明了以升序进行排序的行为. Queue接口,声明了队列行为,队列通常是先进先出的列表 Deque接口,扩展了Queue接口,声明了双端队列的行为.双端队列可以像标准 ...
- Jmeter工具进行一个完整的接口测试
Jmeter工具进行一个完整的接口测试 1.创建一个线程组 通俗的讲一个线程组,,可以看做一个虚拟用户组,线程组中的每个线程都可以理解为一个虚拟用户. 2.输入线程组名字 3.添加一个cookie ...