Ich habe ein einfaches Reverse-Proxy-Setup mit nginx (das in einem Docker-Container mit certbot läuft)https://github.com/umputun/nginx-le) als Webserver example.com
, 192.168.0.220:80
auf dem meine App läuft. Es gibt die Konfiguration:
server {
listen 443 ssl;
server_name example.com;
charset utf-8;
ssl_certificate SSL_CERT;
ssl_certificate_key SSL_KEY;
ssl_trusted_certificate SSL_CHAIN_CERT;
location /smarthome/ {
proxy_pass http://192.168.0.220:80/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Origin '';
}
}
Und eine Webseite mit statischen Ressourcen, die wie folgt definiert sind<script src="/js/home.js"></script>
Das Problem ist, dass beim Zugriff example.com/smarthome
meine statischen Ressourcen nicht geladen werden. In der Konsole:
https://example.com/js/home.js/smarthome/smarthome/smarthome/smarthome/smarthome/smarthome/smarthome/smarthome/smarthome/smarthome/smarthome/smarthome/smarthome/smarthome/smarthome/smarthome/smarthome/smarthome/smarthome/smarthome net::ERR_TOO_MANY_REDIRECTS
Ich habe erwartet, statische Ressourcen zu erhalten https://example.com/smarthome/js/home.js
, aber es scheint, als gerät man in eine Umleitungsschleife.
Ich übersehe vielleicht etwas ganz Einfaches, kann aber keine Lösung finden, während mich die Frustration überkommt. Vielen Dank im Voraus für die Hilfe!
Antwort1
Basierend auf Ihrer Nginx-Konfiguration müssen Sie den Stammspeicherort definieren. Andernfalls wird die Schleife immer umgeleitet.
Sie können die Konfigurationsdatei wie folgt erstellen:
server {
listen 443 ssl;
server_name example.com;
charset utf-8;
ssl_certificate SSL_CERT;
ssl_certificate_key SSL_KEY;
ssl_trusted_certificate SSL_CHAIN_CERT;
location / {
proxy_pass http://192.168.0.220:80;
}
location /smarthome/ {
proxy_pass http://192.168.0.220:80/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Origin '';
}
}