NginxProxyManager / nginx-proxy-manager

Docker container for managing Nginx proxy hosts with a simple, powerful interface
https://nginxproxymanager.com
MIT License
22.41k stars 2.6k forks source link

NPM proxy to nginx - error 502 #2897

Open dszymczuk opened 1 year ago

dszymczuk commented 1 year ago

Checklist

Describe the bug Got 502 error when made proxy from NPM to nginx.

Nginx Proxy Manager Version v2.10.2

To Reproduce Steps to reproduce the behavior:

  1. Use officially nginx image without any for application (app-front)

Zrzut ekranu 2023-05-7 o 15 24 29

  1. Run NPM

Zrzut ekranu 2023-05-7 o 15 25 14

  1. Make proxy to application via NPM for frontend

Zrzut ekranu 2023-05-7 o 10 40 56

  1. Make proxy to application via NPM for backend

Zrzut ekranu 2023-05-7 o 10 41 22

  1. Git error 502 when open frontend app. Backend works correctly.

Expected behavior

Make proxy for frontend app correctly.

Operating System Docker - Debian

Additional context

Application is accessible via port 8080 so nginx from frontend part works correctly.

It looks like the problem is between NPM and nginx.

Error logs from NPM (IP 172.23.0.2 is frontend): 2023/05/07 08:45:59 [error] 9579#9579: *1174 connect() failed (111: Connection refused) while connecting to upstream, client: IP_CLIENT, server: krzysiek.dszymczuk.pl, request: "GET / HTTP/2.0", upstream: "http://172.23.0.2:8080/", host: "MYDOMAIN.COM", referrer: "http://MYDOMAIN.COM:8081/"

2023/05/07 08:46:00 [error] 9579#9579: *1174 connect() failed (111: Connection refused) while connecting to upstream, client: IP_CLIENT, server: MYDOMAIN.COM, request: "GET /favicon.ico HTTP/2.0", upstream: "http://172.23.0.2:8080/favicon.ico", host: "MYDOMAIN.COM", referrer: "https://MYDOMAIN.COM/"

shruuub commented 1 year ago

Hi, could you perhaps share relevant nginx logs? Seems like a common problem I also had before.

dszymczuk commented 1 year ago

No more logs. Just what I pasted.

shruuub commented 1 year ago

Are you sure? I mean the nginx webserver/container.

dszymczuk commented 1 year ago

APP nginx access.log is empty. APP nginx error.log has:

2023/05/22 15:07:48 [notice] 1#1: using the "epoll" event method
2023/05/22 15:07:48 [notice] 1#1: nginx/1.24.0
2023/05/22 15:07:48 [notice] 1#1: built by gcc 12.2.1 20220924 (Alpine 12.2.1_git20220924-r4)
2023/05/22 15:07:48 [notice] 1#1: OS: Linux 4.19.0-10-amd64
2023/05/22 15:07:48 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2023/05/22 15:07:48 [notice] 1#1: start worker processes
2023/05/22 15:07:48 [notice] 1#1: start worker process 29
2023/05/22 15:07:48 [notice] 1#1: start worker process 30

NPM error.log:

2023/05/22 14:58:11 [notice] 411#411: signal process started
2023/05/22 14:58:12 [notice] 429#429: signal process started
2023/05/22 14:58:12 [notice] 441#441: signal process started
2023/05/22 14:58:55 [notice] 578#578: signal process started
2023/05/22 14:59:03 [notice] 611#611: signal process started
2023/05/22 14:59:39 [notice] 730#730: signal process started
2023/05/22 14:59:51 [notice] 775#775: signal process started
2023/05/22 14:59:51 [notice] 793#793: signal process started
2023/05/22 14:59:51 [notice] 808#808: signal process started

NPM Access log is not exist.

shruuub commented 1 year ago

Sorry for the late response, but it's actually pretty simple. For the frontend you simply need to use port 80. You can remove the ports: part in your docker-compose.yml. since you got all the containers in one network :)

dszymczuk commented 1 year ago

I commented out the port part and it works. But why it doesn't work when I set 3000:80 and set in NPM to http://app-frontend:3000?

shruuub commented 1 year ago

I commented out the port part and it works. But why it doesn't work when I set 3000:80 and set in NPM to http://app-frontend:3000?

That's because setting 3000:80 forwards the port to the network (e.g. 127.0.0.1:3000, could also be a home IP or external IP). If you want to use the port, you'd need to use your local ip. Generally tho, how you do it now, with seperate hostnames and ports, is the best approach since it secures the service itself by only allowing external traffic through thr reverse proxy. :D I hope that's understandable, feel free to ask if you have any further questions.

github-actions[bot] commented 8 months ago

Issue is now considered stale. If you want to keep it open, please comment :+1: