In a Linux system, only the root user can bind to ports under 1024 by default, and ordinary users need to bind ports below 1024, the basic method is to use the Nginx agent forwarding or operating system iptables port forwarding two ways, This article will take Tomcat as an example, run Tomcat directly with a normal user, and have the Tomcat program bind to port 80 or forward proxy to Tomcat's 8080 port.
To make the machine 80 port to the client method ask, you can refer to the following ways:
Iptables Port Forwarding Method
Nginx Agent Mode
Setcap Way
1, Iptables Way
RHEL 7
#firewall-cmd–permanent–add-forward-port=port=80:proto=tcp:toport=8080
RHEL 7 Previous version
#iptables-T nat-a prerouting-p tcp–dport 80-j redirect–to-port 8080
2. Install Nginx and forward 80 ports to 8080
Listen 80;
Location/{
Proxy_pass http://localhost:8080;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
}
3, Setcap Way
#setcap ' Cap_net_bind_service=ep '/usr/local/jdk1.8.0/jre/bin/java
/usr/local/jdk1.8.0/jre/bin/java the Java Environment Program that is run for Tomcat, or the absolute path to another program if it is another program.
In addition: EP for permanent entry into force
Query man 7 capabilities through man help
Cap_net_bind_service
Bind a socket to Internet domain privileged ports (port numbers less than 1024).