修改server.xml中Shutdown port,Connector port,ajp port和Redirect port的端口
从8080端口改变端口
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
将端口80的TCP连接传递给端口8080
在Linux下检查iptables特性是否处于enabled状态
[root@wls-132 bin]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@wls-132 bin]#
如果看到相似的输出,一般就是可用状态。
通过下列两条命令,你可以让80端口的所有TCP连接按机器配置寻址到所有网络目的地址
[root@wls-132 bin]# iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
[root@wls-132 bin]# iptables -t nat -I OUTPUT -p tcp --dport 80 -j REDIRECT --to-ports 8080
[root@wls-132 bin]#
(实验时访问不到应用)如果只想把机器配置的一个IP地址的连接传递给8080端口,那么可以再追加目的地址ip是选择性的使用--dst切换开关,如下所示:
[root@wls-132 bin]# iptables -t nat -I PREROUTING -p tcp --dst 192.168.1.106 --dport 80 -j REDIRECT --to-ports 8081
[root@wls-132 bin]# iptables -t nat -I OUTPUT -p tcp --dst 192.168.1.106 --dport 80 -j REDIRECT --to-ports 8081
[root@wls-132 bin]#
查看过滤规则
[root@wls-132 bin]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- anywhere 192.168.1.106 tcp dpt:http redir ports 8081
REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 8081
REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 8080
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- anywhere 192.168.1.106 tcp dpt:http redir ports 8081
REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 8081
REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 8080
删除过滤规则
[root@wls-132 bin]# iptables -t nat -D PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
[root@wls-132 bin]# iptables -t nat -D PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8081
[root@wls-132 bin]# iptables -t nat -D OUTPUT -p tcp --dport 80 -j REDIRECT --to-ports 8080
[root@wls-132 bin]# iptables -t nat -D OUTPUT -p tcp --dport 80 -j REDIRECT --to-ports 8081
重定向方法的缺点在于:为了显示真实的端口,Tomcat要重写URL。
假定访问的www.example.com。如果一个用户在其浏览器地址位置输入
http://www.example.com/,那么依Web应用程序的内容而定,Tomcat会对重写该地址,
且该用户会在自己的浏览器位置看到http://www.example.com:8080/index.html的地址。
Tomcat会认定请求来源与8080端口,因为他在8081端口上打开了web服务连接器,因此无论何时发送重定向,
它都会追加上端口号8080,除非按如下方式在server.xml连接器配置文件中增加了proxyPort="80"的信息:
<Connector port="8081" protocol="HTTP/1.1" proxyPort="80"
connectionTimeout="20000"
redirectPort="8444" />
如果Tomcat充当了主页功能,可以设置proxyName="www.example.com"。
iptables参考:http://caisangzi.blog.51cto.com/6387416/1286432;
http://hi.baidu.com/maimixiande/item/7a54d4c2caac0b25ee4665c0