普通用户无法启动监听80端口

一、问题

网站绑定域名后直接通过域名访问使用的是80端口,因此tomcat须监听80端口,而为了安全起见tomcat一般不用root身份运行,综上,需要以普通用户来运行监听80端口的tomcat。此时就会启动失败,报没有权限,因为只有root身份才能监听1024以下的熟知端口。

二、解决

(以下未经验证)

There are a few different solutions to work around this:

  1. Install and configure Apache or nginx as a reverse proxy server, which can be started as root to open the port, and then downgrade its privileges back to a normal user.
  2. Set up a firewall on the server using iptables or an alternative, so that the lower port number is forwarded internally to a higher port number listened by Confluence.
  3. Use jsvc, which is able to open ports as root, and then downgrade privileges.
  4. Use authbind to grant privileges for a non-root user to open a privileged port.

1、通过iptables进行端口转发

  1. tomcat监听8080(其他非熟知端口皆可)端口,直接执行 sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080 将对80端口的请求转发到8080端口。
  2. iptables规则设置后都是即时生效的,但在机器重启后iptables中的配置信息会被清空。因此可以将这些配置保存下来,让iptables在interface启动时自动被加载:

(1)保存防火墙规则: sudo iptables-save > /etc/zsmiptables.rules 

(2)编辑/etc/network/interfaces,在末尾加一行:pre-up iptables-restore < /etc/zsmiptables.rules

参考资料:

1、linux配置本地tomcat应用80端口转发 

2、ubuntu 14,15的iptables重启保存命令 

(前者言将iptables-restore < /etc/zsmiptables.rules放到一脚本里置于/etc/network/if-pre-up.d/下,但一直不成功;改用后者所言将iptables-restore < /etc/zsmiptables.rules加到/etc/network/interfaces末尾成功了)

2、通过isvc

jsvc能以root角色使用端口,因此借助之即可。另外,这种方式也把tomcat做成了服务,能够开机自己启动。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值