一、打开tomcat安装目录下conf/server.xml这个文件
在server.xml文档中找到

</Engine>
</Service> 

接着添加上面添加以下内容(暂时先说分为三种方式):
第一种:
<Host name="www.haokan946.cn" debug="0" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> 
<Context path="" docBase="www" debug="0" reloadable="true" crossContext="true"/> 
<Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="www_5sai_log." suffix=".txt" 
timestamp="true"/> 
</Host>

以上的内容就是在Tomcat的webapps目录下新建一个www文件夹作为www.haokan946.cn这个域名的主目录

第二种:
<Host name="test.5sai.net.cn" debug="0" appBase="C://test/www" unpackWARs="true" autoDeploy="true">
<Context path="" docBase="."/> 
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="test_5sai_access_log."

suffix=".txt" pattern="common" resolveHosts="false"/>
<Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="test_5sai_log." suffix=".txt" timestamp="true"/>
</Host>

以上内容的意思就是在C盘test文件夹下面建立一个www文件夹作为test.5sai.net.cn这个域名的主目录

第三种,如果是linux系统的/var/www作为test.5sai.net.cn这个域名的主目录的话内容如下:

<Host name="test.5sai.net.cn" debug="0" appBase="/var/www" unpackWARs="true" autoDeploy="true">
<Context path="" docBase="."/> 
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="test_5sai_access_log."

suffix=".txt" pattern="common" resolveHosts="false"/>
<Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="test_5sai_log." suffix=".txt" timestamp="true"/>
</Host>

再补充一种
<Host name="www.haokan946.cn" debug="0" unpackWARs="true"> 
<Valve className="org.apache.catalina.valves.AccessLogValve" 
directory="/var/log/tomcat" prefix="www_5sai_access_log." suffix=".txt" 
pattern="common"/> 
<Logger className="org.apache.catalina.logger.FileLogger" 
directory="/var/log/tomcat" prefix="www_5sai_log." suffix=".txt" 
timestamp="true"/>

<Context path="" docBase="/var/www" debug="0" reloadable="true"/> 
</Host>

域名www.haokan946.cn的主目录为/var/www 该站点的所有访问LOG放在/ar/log/tomcat里面

测试:
windows用户打开C:/WINDOWS/system32/drivers/etc的hosts这个文件,
linux用户打开/ect的hosts文件或者vi /ect/hosts
修改内容如下
127.0.0.1 localhost
127.0.0.1 www.haokan946.cn
127.0.0.1 test.5sai.net.cn

然后打开浏览器直接输入网址测试!

linux中设置虚拟域名的更多相关文章

  1. linux 中配置假域名来测试

    1.linux中配置假域名 找到hosts文件进行编辑 命令:vim /etc/hosts 配置: #centos(本机IP)192.168.1.179 www.imooc.com(假域名,自己设置) ...

  2. linux下配置虚拟域名

    linux下配置虚拟域名 1.hosts文件位置! /etc/hosts 2.增加一行 127.0.0.1 xxxxx 3.修改apache中的vhosts vi /etc/httpd/extra/h ...

  3. 在linux中设置静态ip地址

    在linux中设置静态ip地址1.在终端中输入:vi /etc/sysconfig/network-scripts/ifcfg-eth0 2.开始编辑,填写ip地址.子网掩码.网关.DNS等[root ...

  4. wamp 2.5 开放访问权限和设置虚拟域名

    开放访问权限 D:\wamp\bin\apache\apache2.4.9\conf  里的 httpd.conf 搜索www   把 Require local 改为 Require all gra ...

  5. wamp2.5怎么设置虚拟域名

    换了台电脑~好不顺手.老大的机器上装的是wamp.几年没用差点连怎么设置虚拟域名都忘记了.自己写点东西~做个备忘吧. 首先,版本 然后在网上百度一堆七七八八的.做的时候没那么复杂.跟phpstudy差 ...

  6. Linux 中的虚拟网络接口

    独立博客地址:https://ryan4yin.space/posts/linux-virtual-network-interfaces/ 本文用到的字符画工具:vscode-asciiflow2 L ...

  7. Linux中设置服务自启动的三种方式

    有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统服务 主要用三种方式进行这一操作: ln -s                       在/etc/rc.d/rc*.d目录中建立/e ...

  8. [转]Linux中设置服务自启动的三种方式

    from:http://www.cnblogs.com/nerxious/archive/2013/01/18/2866548.html 有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统 ...

  9. [Apache] 2.2与2.4版本在设置虚拟域名时的小差别

    Apache服务器配置虚拟步骤: 1.在httpd.conf中将附加配置文件httpd-vhosts.conf包含进来,接着在httpd-vhosts.conf中写入如下配置: #LoadModule ...

随机推荐

  1. Python3解leetcode Path Sum III

    问题描述: You are given a binary tree in which each node contains an integer value. Find the number of p ...

  2. 笨办法学Python(learn python the hard way)--练习程序21-30

    下面是练习21-30,基于python3 #ex21.py 1 def add(a, b): print("ADDING %d + %d" %(a, b)) return a+b ...

  3. php常用端口号

    常见端口号 Nginx 80 Nginx (“engine x”) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器. MySQL 3306 MySQL是一种关系数据 ...

  4. Linux shell - scp命令用法

    例子: 远程复制一个文件从服务器A (172.0.0.0) /home/test/file1.txt 到 服务器B (172.0.0.1) /home/test 服务器A和服务器B的用户是 test ...

  5. 文件上传: FileItem类、ServletFileUpload 类、DiskFileItemFactory类

    文件上传: ServletFileUpload负责处理上传的文件数据,并将表单中每个输入项封装成一个FileItem对象中, 在使用ServletFileUpload对象解析请求时需要根据DiskFi ...

  6. 牛客 打印N个数组整体最大的Top K

    题目链接:https://www.nowcoder.com/practice/5727b69bf80541c98c06ab90cf4c509e?tpId=101&tqId=33102& ...

  7. 20190821 On Java8 第十一章 内部类

    第十一章 内部类 一个定义在另一个类中的类,叫作内部类. 链接外部类 内部类是一种名字隐藏和组织代码的模式. 内部类拥有其外围类的所有元素的访问权. 内部类 .this 和 .new的使用 this: ...

  8. libOpenThreads库链接冲突错误

    最近在linux 上安装了3.7.0版本的OpenSceneGraph,而在安装之前没有完全卸载之前安装的3.6.3版本,导致在编译程序链接时出现库引用冲突,在便以后出现以下警告信息: /usr/bi ...

  9. JavaScript DoublyLinkedList

    function DoublyLinkedList() { var Node = function(element) { this.element = element; this.next = nul ...

  10. jmeter处理接口加密和解密

    https://www.liangzl.com/get-article-detail-39672.html https://www.cnblogs.com/artoftest/p/7277996.ht ...