A
A
Anatoly Bereznyak2018-07-26 14:25:53
Nginx
Anatoly Bereznyak, 2018-07-26 14:25:53

How to figure out how Apache does port forwarding?

Hello:
I have a macOS Server, with Profile manager and some other services that need Apache. And local development is underway, for which nginx is needed.
By default, if nginx does not start at system startup, Apache reserves ports 80 and 443.
If nginx starts earlier at system startup, then it occupies port 80, and Apache somehow magically makes a failover and performs port forwarding (lines 3 and 6 ), but I can’t understand how he does it, I want to find out.
My goal is to leave ports 80 and 443 free (not reserving them by running nginx at system startup, causing a failover), so that I can run nginx locally or from docker and reproduce this port forwarding 127.0.0.1:80->127.0. 0.1:49800 and 127.0.0.1:49800->127.0.0.1:80 not in some magical way, but under control.
Getting rid of Apache is impossible. You can't run it either.

| => sudo lsof -nP -i4TCP | grep ':80'
Password:
nginx       85         root    7u  IPv4 0x395c143ba29ae4d1      0t0  TCP *:80 (LISTEN)
httpd      108         root    4u  IPv6 0x395c143ba18ae7c9      0t0  TCP *:8080 (LISTEN)
nginx      246       nobody    3u  IPv4 0x395c143bac8d30f1      0t0  TCP 127.0.0.1:80->127.0.0.1:49800 (ESTABLISHED)
nginx      246       nobody    7u  IPv4 0x395c143ba29ae4d1      0t0  TCP *:80 (LISTEN)
httpd      256         _www    4u  IPv6 0x395c143ba18ae7c9      0t0  TCP *:8080 (LISTEN)
devicemgr  288   _devicemgr   10u  IPv4 0x395c143bc0a270f1      0t0  TCP 127.0.0.1:49800->127.0.0.1:80 (ESTABLISHED)
httpd      447         root    4u  IPv6 0x395c143ba61f0a49      0t0  TCP *:80 (LISTEN)
httpd      451         _www    4u  IPv6 0x395c143ba61f0a49      0t0  TCP *:80 (LISTEN)
httpd      452         _www    4u  IPv6 0x395c143ba61f0a49      0t0  TCP *:80 (LISTEN)
httpd      453         _www    4u  IPv6 0x395c143ba61f0a49      0t0  TCP *:80 (LISTEN)
httpd      454         _www    4u  IPv6 0x395c143ba61f0a49      0t0  TCP *:80 (LISTEN)
httpd      455         _www    4u  IPv6 0x395c143ba61f0a49      0t0  TCP *:80 (LISTEN)
httpd      946         _www    4u  IPv6 0x395c143ba61f0a49      0t0  TCP *:80 (LISTEN)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Maslov, 2018-08-02
@Bezk

for example the first 3 rows:
nginx 85 root 7u IPv4 0x395c143ba29ae4d1 0t0 TCP *: 80 (LISTEN)
httpd 108 root 4u IPv6 0x395c143ba18ae7c9 0t0 TCP *: 8080 (LISTEN)
nginx 246 nobody 3u IPv4 0x395c143bac8d30f1 0t0 TCP 127.0.0.1:80->127.0 .0.1:49800 (ESTABLISHED)
the first 2 lines are nginx and apache listening on ports 80 and 8080 respectively (as it is written in brackets LISTEN - listening), but the 3rd line is an established connection through nginx, it is written in brackets - ESTABLISHED. Connection established on port 80, forwarded to random 49800.
I either don’t understand what kind of problem you want to invent for yourself out of the blue, or you just didn’t think to change the port in the nginx config. by default, the /etc/nginx/nginx.conf config and run it as you like, if you want to contact Apache on port 80 so that it forwards you to nginx, when accessing a specific domain, then you need to finish the Apache config (google - this is pretty simple)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question