Unable to resolve the url with location tag

Viewed 58

I have install let's encrypt with ngnix. Using the IP address , the url resolves i.e.

 http://<some-ip-address>:8000/subgraphs/name/foo/bar/graphql

I add a location tag to the ngnix config

     location /the_graph {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            rewrite ^/the_graph(.*) /$1 break;
            proxy_pass http://127.0.0.1:8000;
            try_files $uri $uri/ =404;
    

which should resolve

https://<some_domain_name>/the_graph/subgraphs/name/foo/bar/graphql 

However it resolves to a 404.

I would appreciate any assistance on this

1 Answers

try_files is primarily for serving local files, but you want to use proxy_pass, so you need to remove it, otherwise it will generate a 404 response.

You are rewriting the URL to remove the prefix /the_graph.

You can either use proxy_pass to do this:

location /the_graph/ {
    proxy_pass http://127.0.0.1:8000/;
}

Notice the trailing / on both the location and proxy_pass values.


Or a rewrite...break:

location /the_graph {
    rewrite ^/the_graph(.*) $1 break;
    proxy_pass http://127.0.0.1:8000;
}

The capture ($1) already includes the leading / so you must not add another.

Related