配置tomcat虚拟主机

配置Tomcat监听80端口

修改tomcat的默认端口,将其改为80端口,在Connector port端口指定的地方修改为80端口,wq保存退出

[[email protected] ~]# vim /usr/local/tomcat/conf/server.xml
 ?  <Connector port="80" protocol="HTTP/1.1"
 ? ? ? ? ? ? ? connectionTimeout="20000"
 ? ? ? ? ? ? ? redirectPort="8443" />

关闭其他web服务,如nginx的服务,以免出现占用端口

[[email protected] ~]# /etc/init.d/nginx stop
Stopping nginx (via systemctl): [ 确定 ]

重新启动tomcat服务,tomcat没有nginx类似的服务启动重启脚本,只能将服务先停止然后再启动

[[email protected] ~]# /usr/local/tomcat/bin/shutdown.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/jdk1.8
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[[email protected] ~]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/jdk1.8
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.

查看tomcat的端口占用,8005端口是tomcat服务的管理端口,只有在这个端口启动监听后tomcat才能够正常提供访问

[[email protected] ~]# netstat -ntlp |grep 80
tcp6 0 0 :::80 :::* LISTEN 19270/java ? ? ? ? ?
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 19270/java ? ? ? ? ?
tcp6 0 0 :::8009 :::* LISTEN 19270/java
```? ? ?
测试通过80端口访问tomcat,curl不指定端口默认会是80端口

[[email protected] ~]# curl -I 192.168.1.234
HTTP/1.1 200
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Sat, 18 Aug 2018 22:26:12 GMT

# tomcat虚拟主机

添加tomcat虚拟主机
编辑tomcat的server.xml配置文件,添加一个虚拟主机配置

[[email protected] ~]# vim /usr/local/tomcat/conf/server.xml
<Host name="www.abc.com" appBase=""
? ? ? ? ? ?unpackWARs="true" autoDeplo="true"
? ? ? ? ? ?xmlValidation="false" xmlNamespaceAware="false">
? ? ? <Context path="" docBase="/data/wwwroot/abc/" debug="0"
? ? ? ? ? reloadable="true" crossContext="true"/>
? ? </Host>

server的虚拟主机配置说明
在<Host></Host>这个标签中定义tomcat的虚拟主机,其中docBase和appBase来定义网站文件的存放路径,如果不定义docBase,则默认会认为网站文件存放在appBase/ROOT目录下,如果定义了docBase,则就会以docBase定义的目录为主了,生效的是docBase中定义的目录,如果这步没有定义正确则会遇到404的访问问题
appBase是存放应用的目录,通常是把war包放在该目录下,tomcat会自动解压出一个程序目录出来

使用tomcat部署一个博客项目
首先下载项目的war包,拷贝war包到/usr/local/tomcat/webapps目录当中,让tomcat自动解压出文件目录,把解压的目录改为其他名字。之后删除war包,如下操作

[[email protected] webapps]# cp /usr/local/src/zrlog-2.0.2-5ebb1f3-release.war .
[[email protected] webapps]# ls
docs examples host-manager manager ROOT zrlog-2.0.2-5ebb1f3-release.war
[[email protected] webapps]# mv zrlog-2.0.2-5ebb1f3-release zrlog
[[email protected] webapps]# rm -rf zrlog-2.0.2-5ebb1f3-release.war
[[email protected] webapps]# ls
docs examples host-manager manager ROOT zrlog

之后访问192.168.1.234/zrlog的安装页面,192.168.1.234是服务器本机ip地址
安装界面如下

![](http://i2.51cto.com/images/blog/201808/30/2bd86ede47b4a7e4769939df065f6cdb.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
这里我们需要为zrlog创建名字为zrlog存储数据的数据库,并需要创建zrlog库并给予一定的权限,使用测试用户zrlog登录并验证数据库用户正确性

mysql> create database zrlog;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on zrlog.* to ‘zrlog‘@127.0.0.1 identified by ‘[email protected]‘ ;
Query OK, 0 rows affected, 1 warning (0.01 sec)
[[email protected] webapps]# mysql -uzrlog -h127.0.0.1 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 55
Server version: 5.7.22 Source distribution
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql> show databases;
+--------------------+
| Database ? ? ? ? ? |
+--------------------+
| information_schema |
| zrlog ? ? ? ? ? ? |
+--------------------+
2 rows in set (0.00 sec)

创建后按提示写入连接数据库的用户和密码进行下一步操作
安装后进入的管理控制页面
![](http://i2.51cto.com/images/blog/201808/30/279adb904f5238af3a6c11d7aa43335a.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

将web文件目录移动位置,使用定义的域名进行访问,这里将zrlog目录下所有的文件拷贝或移动到指定的网站文件目录下,注意不是拷贝zrlog本身,这和指定的网站目录路径有关

[[email protected] webapps]# ls
docs examples host-manager manager ROOT zrlog
[[email protected] webapps]# cd /data/wwwroot/abc/
[[email protected] abc]# cp -rf /usr/local/tomcat/webapps/zrlog/* .
[[email protected] abc]# ls
admin assets error favicon.ico include META-INF WEB-INF
[[email protected] abc]# pwd
/data/wwwroot/abc

重新启动tomcat,使server.xml中的配置生效

[[email protected] abc]# /usr/local/tomcat/bin/shutdown.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/jdk1.8
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[[email protected] abc]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/jdk1.8
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.

查看tomcat启动的端口,tomcat只监听80、8009和8005端口,其他端口则是由网站程序监听的

[[email protected] abc]# netstat -ntlp |grep java
tcp6 0 0 127.0.0.1:45711 ::: LISTEN 20309/java ? ? ? ? ?
tcp6 0 0 127.0.0.1:25711 :::
LISTEN 20309/java ? ? ? ? ?
tcp6 0 0 :::80 ::: LISTEN 20254/java ? ? ? ? ?
tcp6 0 0 127.0.0.1:53080 :::
LISTEN 20276/java ? ? ? ? ?
tcp6 0 0 127.0.0.1:55711 ::: LISTEN 20309/java ? ? ? ? ?
tcp6 0 0 127.0.0.1:8005 :::
LISTEN 20254/java ? ? ? ? ?
tcp6 0 0 127.0.0.1:43080 ::: LISTEN 20276/java ? ? ? ? ?
tcp6 0 0 127.0.0.1:23080 :::
LISTEN 20276/java ? ? ? ? ?
tcp6 0 0 :::8009 :::* LISTEN 20254/java ?

在定义的配置中,Host name是定义的域名,docBase定义的是网站存储的目录,appBase是存储应用的默认目录,如果设置了docBase,则appBase不需要配置

<Host name="www.aaa.com" appBase=""
? ? ? ? ? ?unpackWARs="true" autoDeplo="true"
? ? ? ? ? ?xmlValidation="false" xmlNamespaceAware="false">
? ? ? <Context path="" docBase="/data/wwwroot/abc/" debug="0"
? ? ? ? ? reloadable="true" crossContext="true"/>
? ? </Host>



在windows的host中写入测试解析的主机,在浏览器中访问定义的域名,查看是否能直接通过域名进行访问

为了防止浏览器反馈给我们缓存的页面,需要使用ctrl+F5来进行强制刷新请求,返回访问结果

![](http://i2.51cto.com/images/blog/201808/30/3c852a5aa558e1219236bf5bde6d2d7a.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

原文地址:http://blog.51cto.com/8844414/2167048

时间: 2024-10-14 17:16:59

配置tomcat虚拟主机的相关文章

16.4 配置Tomcat监听80端口 16.5/16.6/16.7 配置Tomcat虚拟主机 16.8 Tomcat日志

16.4 配置Tomcat监听80端口 16.5/16.6/16.7 配置Tomcat虚拟主机 16.8 Tomcat日志 扩展 邱李的tomcat文档 https://www.linuser.com/forum.php?mod=forumdisplay&fid=37 JAR.WAR包区别 http://blog.csdn.net/lishehe/article/details/41607725 tomcat常见配置汇总 http://blog.sina.com.cn/s/blog_4ab26b

配置Tomcat监听80端口 配置Tomcat虚拟主机 Tomcat日志

配置Tomcat监听80端口 • vim /usr/local/tomcat/conf/server.xml Connector port="8080" protocol="HTTP/1.1"修改为Connector port="80" protocol="HTTP/1.1" • /usr/local/tomcat/bin/shutdown.sh • /usr/local/tomcat/bin/startup.sh 配置Tom

配置Tomcat监听80端口、配置Tomcat虚拟主机、Tomcat日志

一. 配置Tomcat监听80端口 vim /usr/local/tomcat/conf/server.xmlConnector port="8080" protocol="HTTP/1.1"修改为Connector port="80" protocol="HTTP/1.1"/usr/local/tomcat/bin/shutdown.sh/usr/local/tomcat/bin/startup.sh 二.配置Tomcat虚

16.4 配置Tomcat监听80端口 16.5/16.6/16.7 配置Tomcat虚拟主机 16

16.4 配置Tomcat监听80端口 16.5/16.6/16.7 配置Tomcat虚拟主机 16.8 Tomcat日志 原文地址:http://blog.51cto.com/13227377/2137413

Tomcat监听80端口、配置Tomcat虚拟主机、Tomcat日志

配置Tomcat监听80端口 1.配置Tomcat服务的访问端口 Tomcat默认启动的端口是8080,如果你想修改为80,则需要修改server.xml文件. [[email protected] src]# vim /usr/local/tomcat/conf/server.xml 按如下需求更改: 找到Connector port="8080" protocol="HTTP/1.1"修改为Connector port="80" protoc

配置Tomcat监听80端口, 配置Tomcat虚拟主机,Tomcat日志

配置Tomcat监听80端口 编辑配置文件vim /usr/local/tomcat/conf/server.xml在里面找到8080<Connector port="8080" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443" />将里面的8080改为80,然后保存退出.然后先关闭tomcat/usr/local/tomcat/bin/

Nginx快捷配置Tomcat虚拟主机

作者:fbysss QQ:溜酒酒吧酒吧吾散 blog:blog.csdn.net/fbysss 声明:本文由fbysss原创,转载请注明出处 典型场景: Tomcat的webapps目录中,有两个应用:app1.app2,如果没有nginx,我们的访问路径为: http://www.domainname.com:8080/app1 http://www.domainname.com:8080/app2 端口号暴露给用户很不好看也不安全.修改Tomcat配置文件的做法,也可以,但感觉麻烦一些,在这

配置Tomcat虚拟主机-2

docBase,这个参数用来定义网站的文件存放路径,如果不定义,默认是在appBase/ROOT下面,定义了docBase就以该目录为主了.其中appBase和docBase可以一样.在这一步操作过程中很多同学遇到过访问404的问题,其实就是docBase没有定义对. appBase为应用存放目录,通常是需要把war包直接放到该目录下面,它会自动解压成一个程序目录下面我们通过部署一个java的应用来体会appBase和docBase目录的作用下载zrlog wget http://dl.zrlo

server.xml引入子文件配置(tomcat虚拟主机)[转]

在配置tomcat虚拟主机时候,如何每一个虚拟主机写成单独文件,server.xml包含这些子文件? 如以下<OneinStack>中,添加JAVA环境虚拟主机后tomcat配置文件详情: /usr/local/tomcat/conf/server.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE server-xml [ <!ENTITY localhost-vhost S