目录
- 目录
- 互联网上常用协议以及其工作端口
- 虚拟目录的映射方式
- Tomcat配置虚拟目录
- 不重启Tomcat配置虚拟目录的方式
- 让tomcat自动映射
- 配置虚拟主机
- 使用Java编写最简单的服务器程序
互联网上常用协议以及其工作端口
协议 | 端口 |
http | 80 |
smtp | 25 |
pop3 | 110 |
ftp | 23 |
https | 443 |
虚拟目录的映射方式
Tomcat配置虚拟目录
在Tomcat的server.xml配置文件中的Host标签内,添加:
其中path属性表示对外访问的路径;docBase表示本地的Web资源路径。注:配置完成后需要重启服务器。因此,在实际生产中,并不推荐使用该方法。
如配置为:
即配置了一个缺省的Web应用,默认访问的Web应用。
不重启Tomcat配置虚拟目录的方式:
在Tomcat服务器的conf/[enginename]/[hostname]/目录下创建任意以.xml结尾的文件,则文件名为对外访问的Web路径,如test.xml。
test.xml中的配置如下:
则在浏览器中访问 http://localhost:8080/test/1.html
,即访问的是服务器C盘下面的web目录下的1.html文件。
多级目录的配置,如:test#t2#t3.xml
,则在浏览器中访问 http://localhost:8080/test/t2/t3/1.html
,同样访问的是服务器C盘下这个web目录的Web应用。
如配置文件命名为 ROOT.xml(此时需要重启服务器),则配置了默认的Web应用,该应用指向的是ROOT.xml中配置的web目录下的应用。则在浏览器中可以直接访问:http://localhost:8080/1.html
,访问的是服务器C盘web目录下的Web资源。
让tomcat自动映射
tomcat服务器会自动管理webapps目录下的所有web应用,并把它映射程虚拟目录。换句话说,tomcat服务器webapps目录中的web应用,外界可以直接访问。
配置虚拟主机
在Tomcat的server.xml配置文件中配置Host标签,如:
同时修改本地C:\Windows\System32\drivers\etc
下的HOSTS文件,加入:
其中 192.168.1.22
应相应修改为对应本机的ip地址(内网地址)。
在浏览器中直接访问:http://www.sina.com/pc/1.html
(如果端口也配置为80的话),则访问的是服务器C盘sina目录下的pc Web应用下的1.html页面。
使用Java编写最简单的服务器程序
程序运行后,访问http://localhost:9999
可以看到 1.html 页面的内容。