標籤:文章 centos 網上
有效修改Tomcat6預設連接埠(Ubuntu Server,CentOS)
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就好用。原來,從Ubuntu 10.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 *:*
$
現在好了。
對於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://chenshengang.blog.51cto.com/4399161/1629914
有效修改Tomcat6預設連接埠(Ubuntu Server,CentOS)