Sobes.tech
Senior

The binary tries to bind to port 80, but it is already occupied by nginx. How to run this binary?

sobes.tech AI

Answer from AI

Port 80 is a privileged port, and if it is already occupied by nginx, it is not possible to directly run another binary that tries to bind to the same port.

Solution options:

  1. Change the port of the binary — if possible, run it on another port, for example 8080.

  2. Reconfigure nginx — make nginx a proxy that listens on port 80 and proxies requests to the port where the binary is running.

  3. Stop nginx — if nginx is not needed, stop it to free the port.

  4. Use iptables or firewall for port forwarding — for example, redirect traffic from port 80 to the binary's port.

  5. Run the binary with root privileges (if it requires privileges to bind to port 80) — but this will not solve the problem if the port is already occupied.

Example of reconfiguring nginx for proxying:

server {
    listen 80;
    location / {
        proxy_pass http://127.0.0.1:8080;
    }
}

Thus, nginx listens on port 80, and the binary on 8080, with nginx proxying requests.