用阿里云部署项目并连接微信公众号的小伙伴们应该会遇到一个问题,如果用eclipse远程调试tomcat程序时,回调页面域名无法添加端口号,而root下的tomcat端口已经改为80,那么访问自定义账号下的8080端口成为一个问题。
本文采用将8080端口的请求发送到80端口,采用修改centos(centos7)的机制进行自动转发。由于centos7版本没有iptables-services,故需要安装。如果是centos7一下版本则可以直接打开
- 用root账户将防火墙停止
systemctl stop firewalld.service systemctl disable firewalld.service
-
安装 iptables-services
yum install iptables-services
- 转发端口
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
-
生效配置
service iptables save
最后有iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ] 即设置成功,此时的设置生效在服务器重启后失效,则需要永久设置
-
设置有效
systemctl restart iptables.service systemctl enable iptables.service
设置完成