有效修改Tomcat6預設連接埠(Ubuntu Server,CentOS)

來源:互聯網
上載者:User

標籤:文章   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)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.