0

I am no expert in nginx, so sorry if any information is missing or not complete.

I have a website running under http://server-ip:3000/abc/xyz. This website also loads some assets from http://server-ip:3000/assets, but also some from http://server-ip:3000/abc/xyz/data

I now want to map mydomain.tld to http://server-ip:3000/abc/xyz

Therefore i have these locations:

location / {
   proxy_pass http://upstream123/abc/xyz/;
}
location ~* /assets {
   proxy_pass http://upstream123;
}

I assume I also have to map the data folder as an own location, because the contents of it wont be loaded (404) when accessing via the domain:

location ~* /data {
   proxy_pass http://upstream123/abc/xyz/data;
}

I do all this via OPNsense and at first it accepted this and everything. But it led to some problems and when trying to reload everything and testing the nginx configuration, it tells me: nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block in /usr/local/etc/nginx/nginx.conf:4532

I assume the problem is, that with the root (/) location, it somehow already refers to a deeper path, which then leads to problems when accessing path further down? proxy_pass http://upstream123/data; does not work, I tried this already

I hope I was able to explain the problem detailed enough.

Thanks

5
  • please share the output of nginx -t and /xyz/ should be /xyz
    – djdomi
    Commented Apr 16 at 19:07
  • I removed the trailing slash, but the error remains the same: nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block in /usr/local/etc/nginx/nginx.conf:4532 Commented Apr 17 at 9:27
  • and what is the line 4532?
    – djdomi
    Commented Apr 18 at 4:13
  • The proxy pass line of location ~* /data { proxy_pass http://upstream123/abc/xyz/data; ``` Commented Apr 18 at 13:06
  • update on the question not to the commentary section please
    – djdomi
    Commented Apr 19 at 5:07

1 Answer 1

0

We should assume from the OP that Nginx contains the upstream block:

upstream upstream123 { 
    server server-ip:3000 ; 
    ...
}

I am going to also assume that there is a server block to handle the Virtual Host mydomain.tld as follows:

server {
    listen 80;
    server_name mydomain.tld ;
    ...
}

In that server block one would find the same location blocks as above.

My question is whether the same approach for /assets has been tried with /data ?

location ~* /data {
    proxy_pass http://upstream123 ;
    ...
}

By default, this would request the complete uri including /data and proxy the request for /abc/xyz/data or /this/data/dir or even /this/datadir to server-ip:3000 , just like the location for /assets would work. If it hasn't worked this way, there is a different problem that should be solved rather than trying to mangle Nginx proxy_pass directives.

In this case, Nginx reload is breaking because you are effectively trying to "rewrite" a uri component inside a Regex-based location, and the (nuanced, internal) Nginx rules are preventing this because it won't resolve correctly.

What I realy want to say is "why not serve all URI's without /abc/xyz and simply use that in your public web dir as a "silent" path.

server {
    ...
    server_name mydomain.tld ;
    root /var/www/html/abc/xyz ;

    location / {
        proxy_pass http://upstream123 ;
        ...
    }

}

In this case, it would be expected that literally any path should be found from the Top Level Directory at /var/www/html/abc/xyz such that the web request: http://mydomain.tld/my/image.jpg would attempt access at the Server Resource: /var/www/html/abc/xyz/my/image.jpg

But... I don't want to second-guess your reasons, just wanted you to know there were other ways to handle regularly expected path transforms to make your life easier.

Of course, doing so may create other problems that may not be solved so easily, and it really just depends on the details of your use-case(s)...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .