nginx를 사용하여 간단한 역방향 프록시 설정을 했습니다(certbot이 있는 docker 컨테이너에서 실행됨).https://github.com/umputun/nginx-le)를 웹 서버로 사용 example.com
하고 192.168.0.220:80
내 앱이 실행되는 곳입니다. 구성이 있습니다:
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 '';
}
}
그리고 다음과 같이 정의된 정적 리소스가 있는 웹 페이지<script src="/js/home.js"></script>
문제는 액세스할 때 example.com/smarthome
정적 리소스가 로드되지 않는다는 것입니다. 콘솔에서:
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
그러나 상태 리소스 양식을 얻을 것으로 예상되었지만 https://example.com/smarthome/js/home.js
리디렉션 루프에 들어간 것 같습니다.
아주 간단한 것을 놓칠 수도 있지만, 좌절감이 몰려오면서 해결책을 찾을 수 없습니다. 미리 도움을 주셔서 감사합니다!
답변1
Nginx 구성에 따라 루트 위치를 정의해야 합니다. 그렇지 않으면 항상 루프를 리디렉션합니다.
다음과 같이 구성 파일을 만들 수 있습니다.
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 '';
}
}