0

Problem:

  • I use a nginx proxy_pass directive to redirect https requests with a specific location path in the URI, e.g., https://domain/path/index.html to http://container_ip:port/index.html.
  • This works fine for the initial request.
  • However, if the HTML-file specifies resources to load, clients search these resources without the path, using only the base URL; in the example https://domain/main.css.

Question:
How can I configure nginx so that such resources also are searched at the original path; in the example at https://domain/path/main.css?

Current incorrect nginx configuration:

server {
    listen 443 ssl;
    server_name domain;

    [...]

    location /path/ {
        proxy_set_header Host $host;
        proxy_pass http://container_ip:port/;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header X-Forwarded-For $remote_addr;
    }
}
thando
  • 135
  • 5

1 Answers1

1

Paths to resources are generated by your application. The proper and reliable approach is to fix your application to generate resource URLs with correct paths.

If you want an unreliable solution, you can try using http://nginx.org/en/docs/http/ngx_http_sub_module.html to replace resource URLs in responses that nginx proxies. However, there is a chance of unwanted side effects which can be difficult to diagnose.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63