在Ubuntu上打開Tomcat6的443端口和80端口

Ubuntu下Tomcat6安装配置
本文介绍如何在Ubuntu Server上安装和配置Tomcat6,包括更改默认监听端口从8080到80的方法,并解决使用低于1024端口所需的权限问题。

How to install and configure tomcat 6 in ubuntu server

 
 
 
 
 
 
 
1 Vote

 


Tomcat is a well known and widely used java servlet container. These days I am planning a project, which needs a tomcat 6 in ubuntu server. I found that to make tomcat work in ubuntu is very easy, but you need have a little trick to change your server listening port from 8080 to 80. Here I give you the way that I make it work.

1. Install tomcat 6 in ubuntu

normally, you just need to type the following command to install it

sudo apt-get install tomcat6 tomcat6-admin tomcat6-common tomcat6-user tomcat6-docs tomcat6-examples

2. Start tomcat

 

sudo /etc/init.d/tomcat6 start

Now, you can use your browser to navigate this address:

http://<your ip>:8080

And you will see the tomcat It works! page

Usually, HTTP server works with the port 80, but the default port for tomcat is 8080, that is why we need specify 8080 after your ip address. To change the default port from 8080 to 80, type the following command in the terminal:
sudo vim /etc/tomcat6/server.xml
Find the line contains the following content:

<Connector port="8080"  protocol=...

Change it to

<Connector port="80"  protocol=...

Now restart your tomcat server, you will find the following error if you browse your tomcat log in /var/log/tomcat6/catalina_<your date>.log:

SEVERE: Error starting endpoint

java.net.BindException: Permission denied <null>:80

This is because you dont have the permission to use the port number lower than 1024 in ubuntu. To make it happen, open the /etc/default/tomcat6 file:

sudo vim /etc/default/tomcat6

Find the text:

# 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


uncomment the last line and change it to

AUTHBIND=yes

Save it, and restart your tomcat

sudo /etc/init.d/tomcat6 start

Now you can access your server with the address:

http://<your ip>

### 如何在 Ubuntu 系统上安装配置 Tomcat 要在 Ubuntu 上安装配置 Tomcat 服务器,可以遵循以下详细步骤。这些步骤涵盖了从下载到启动的整个过程。 #### 一、下载并上传 Tomcat 压缩包 首先需要访问 Apache 官方网站下载最新版本的 Tomcat 压缩包。下载完成后,将压缩包上传到 Ubuntu 服务器中[^1]。通常可以通过 SCP 或 FTP 工具完成上传操作。 #### 二、解压配置 Tomcat 使用以下命令解压 Tomcat 压缩包,并将其移动到指定目录 `/opt/tomcat` 中: ```bash sudo tar -xf apache-tomcat-9.0.54.tar.gz -C /opt sudo mv /opt/apache-tomcat-9.0.54 /opt/tomcat ``` 接下来,创建一个专用用户 `tomcat` 并更改文件夹权限以确保安全性: ```bash sudo useradd -r -m -U -d /opt/tomcat -s /bin/false tomcat sudo chown -R tomcat: /opt/tomcat sudo sh -c 'chmod +x /opt/tomcat/bin/*.sh' ``` 上述命令确保了 Tomcat 的运行环境安全且符合最佳实践[^2]。 #### 三、启动 Tomcat 进入 Tomcat 的 `bin` 目录并执行启动脚本: ```bash cd /opt/tomcat/bin sudo ./startup.sh ``` 启动后会显示类似以下信息,表明 Tomcat 已成功启动: ``` Using CATALINA_BASE: /opt/tomcat Using CATALINA_HOME: /opt/tomcat Using CATALINA_TMPDIR: /opt/tomcat/temp Using JRE_HOME: /usr Using CLASSPATH: /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar Tomcat started. ``` 如果未设置 `JRE_HOME` 环境变量,则需要手动配置 Java 路径[^4]。 #### 四、验证 Tomcat 启动 打开浏览器并访问 `http://<server-ip>:8080`,如果看到 Tomcat 的欢迎页面,则说明服务已正常运行[^1]。 #### 五、配置防火墙以允许外部访问 如果系统启用了防火墙,需要添加规则以允许 Tomcat 默认端口 `8080` 的流量: ```bash sudo ufw allow 8080 ``` #### 六、停止 Tomcat 服务 若需要停止 Tomcat 服务,可执行以下命令: ```bash cd /opt/tomcat/bin sudo ./shutdown.sh ``` 通过以上步骤,即可完成在 Ubuntu 系统上安装配置 Tomcat 的全部流程[^1]。 ### 注意事项 确保系统已安装 Java 开发工具包(JDK),因为 Tomcat 需要依赖 Java 运行时环境。可以通过以下命令检查是否已安装 JDK: ```bash java -version ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值