
Ich versuche, mit Nginx einen Reverse-Proxy für einen Docker-Container einzurichten.
Der Docker-Container ist verfügbar und funktioniert auf Port 8000.
Ich möchte den Container über die Adresse mydomain.com:80/mycontainer erreichen können.
Die Kommunikation des Reverse-Proxys mit dem Container scheint erfolgreich zu sein, doch wenn der Container eine Weiterleitung zu seiner Anmeldeseite anfordert, versucht Nginx, die Anmeldeseite auf Port 80 statt auf Port 8000 zu laden, was fehlschlägt.
dies ist meine bisherige Nginx-Konfiguration:
upstream docker-container {
server 127.0.0.1:8000;
}
server {
listen 80;
location /mycontainer {
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://docker-container;
}
}
Das passiert mir, wenn ich laufe wget -S 127.0.0.1/mycontainer
:
wget -S 127.0.0.1/mycontainer
--2021-08-29 20:30:12-- http://127.0.0.1/mycontainer
Connecting to 127.0.0.1:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 302 Found
Server: nginx/1.18.0 (Ubuntu)
Date: Sun, 29 Aug 2021 20:30:12 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 28
Connection: keep-alive
Content-Language: en
X-Frame-Options: SAMEORIGIN
X-Download-Options: noopen
X-Content-Type-Options: nosniff
Referrer-Policy: origin-when-cross-origin
X-XSS-Protection: 1; mode=block
Location: /login
Vary: Accept
Set-Cookie: some cookie
Location: /login [following]
--2021-08-29 20:30:12-- http://127.0.0.1/login <--- HERE IS THE PROBLEM. Should be 127.0.0.1:8000/login
Reusing existing connection to 127.0.0.1:80.
HTTP request sent, awaiting response...
HTTP/1.1 404 Not Found
Server: nginx/1.18.0 (Ubuntu)
Date: Sun, 29 Aug 2021 20:30:12 GMT
Content-Type: text/html
Content-Length: 162
Connection: keep-alive
2021-08-29 20:30:12 ERROR 404: Not Found.
Ich bin auf diesem Gebiet keineswegs ein Profi und bin daher sicher, dass viele Fehler passieren.
Wie kann ich die automatischen Weiterleitungen so einrichten, dass sie auf den richtigen Port (8000) und nicht auf Port 80 verweisen?