linux 下tomcat修改端口

Ubuntu Server 12.04 安装tomcat6和mysql
$ sudo apt-get install sysv-rc-conf tomcat6 mysql-server
$ sudo ufw allow 80/tcp
$ sudo sysv-rc-conf tomcat6 on

修改tomcat端口,我们似乎都知道在这里把8080改成80:
$ sudo vi /etc/tomcat6/server.xml
    <Connector port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               URIEncoding="UTF-8"
               redirectPort="8443" />


网上很多文章写到这里就完事了,但其实改完后tomcat根本不工作,TCP监听端口里没有80,而恢复到8080就好用。原来,从ubuntu10.04起,默认是关闭1024以下端口的,还需要修改以下文件: 
$ sudo vi /etc/default/tomcat6 
# If you run Tomcat on port numbers that are all higher than 1023, then you
# do not need authbind.  It is used for binding Tomcat to lower port numbers.
# NOTE: authbind works only with IPv4.  Do not enable it when using IPv6.
# (yes/no, default: no)
AUTHBIND=no

改成AUTHBIND=yes

$ sudo service tomcat6 restart
$ ss -ln
State      Recv-Q Send-Q        Local Address:Port          Peer Address:Port 
LISTEN     0      50                127.0.0.1:3306                     *:*     
LISTEN     0      100                       *:80                       *:*     
LISTEN     0      128                      :::22                      :::*     
LISTEN     0      128                       *:22                       *:*     
LISTEN     0      1                 127.0.0.1:8005                     *:*     


现在好了。
参考 http://alanjiang.iteye.com/blog/737563


对于Centos6,是另一种情况,系统不允许tomcat用户使用1024以下的端口。所以除了修改 /etc/tomcat6/server.xml,还有这个文件:
# vi /etc/tomcat6/tomcat6.conf
# What user should run tomcat
TOMCAT_USER="tomcat"

# Connector port is 8080 for this tomcat6 instance
CONNECTOR_PORT="8080"


将上面两行改为
TOMCAT_USER="root"
CONNECTOR_PORT="80"

就可以了。但是这样做的安全性怎么样还不清楚,我觉得比较理想的是 Tomcat与Apache HTTPD的集成,感兴趣就搜一下吧。


参考
http://xuejiayue.iteye.com/blog/88370
http://www.cnblogs.com/gnorts/archive/2010/11/24/1886771.html
 

本文出自 “An old newbie” 博客,请务必保留此出处http://panblack.blog.51cto.com/2980687/941044

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值