0

I have an nginx server where I'd like to point any route that begins with /app to a specific file. It's a single page app, so even /app/some/long/route should just return the same index.html file.

location /app { proxy_pass http://my-cdn-host.com/index.html; } 

I'm having 2 problems:

  1. I'm pretty sure that /app/very/long/url does a proxy_pass to http://my-cdn-host.com/index.html/app/very/long/url which is not wanted
  2. It's not clear to me based on the logs exactly what the proxied URL is, so I can't even fully confirm the point above. $proxy_host and $upstream_addr don't have that full information

One final note: even though the file is http://my-cdn-host.com/index.html, I'm unable to access it with just http://my-cdn-host.com/. The index.html needs to be the explicit path.

Is there a way I can serve a single remote file for my location? Thank you

1 Answer 1

0

This is exactly the expected behavior, described in the proxy_pass directive documentation:

If the proxy_pass directive is specified with a URI, then when a request is passed to the server, the part of a normalized request URI matching the location is replaced by a URI specified in the directive:

location /name/ { proxy_pass http://127.0.0.1/remote/; } 

You need to use another proxy_pass behavior feature, described somewhat below:

In some cases, the part of a request URI to be replaced cannot be determined:

...

  • When the URI is changed inside a proxied location using the rewrite directive, and this same configuration will be used to process a request (break):

    location /name/ { rewrite /name/([^/]+) /users?name=$1 break; proxy_pass http://127.0.0.1; } 

    In this case, the URI specified in the directive is ignored and the full changed request URI is passed to the server.

Use the following location block:

location /app { rewrite ^ /index.html break; proxy_pass http://my-cdn-host.com; } 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.