N
N
NewSantaClaus2021-08-17 10:48:21
linux
NewSantaClaus, 2021-08-17 10:48:21

Why wrong file paths after nginx proxy?

I do proxying for one of the applications (there are 3 applications within one domain).

...
    location /crm{
        proxy_pass http://127.0.0.1:5000/;
    }
...


Proxy works well, but. An application that runs on this port pulls its files along the paths
https://my.site/static/css/8.32345p.chunk.css Accordingly, it does not find files

An application created on React
React generates and inserts into html links of the form /static/css/8.32345p.chunk.css
When you open the application at my.site I see the following
image.png

As well as attempts to open the file manually at
https://my.site/crm/static/css/2.3418215a.chunk.css
also fail

Question!!!
How to configure nginx to find files.
Judging by the logic, you need to make sure that they are searched along the path https://my.site/ crm /static/css/8.32345p.chunk.css
But I do not want to affect the application itself and fix it. How can I set it up?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Andrey Barbolin, 2021-08-17
@dronmaxman

Try this.

location /adminka/ {
                rewrite ^/adminka/(.*)$ /$1  break;
                proxy_pass http://127.0.0.1:5000/;
                sub_filter 'src="/'  'src="/adminka/';
                sub_filter 'action="/'  'action="/adminka/';
                sub_filter 'href="/'  'href="/adminka/';
                sub_filter_once off;
                }

K
ky0, 2021-08-17
@ky0

In order for the location url to fail to the proxied resource, it is enough to remove the final slash from the directive proxy_pass.

A
Alexander Falaleev, 2021-08-17
@suffix_ixbt

As an option:
1. Make a symlink from where to where you need it 2. Don't forget to add disable_symlinks off
to the nginx settings ; This directive is supported in http, server, location

S
SagePtr, 2021-08-17
@SagePtr

You seem to have been answered last time. Use paths in nginx with a trailing slash:

location /crm/ {
    proxy_pass http://127.0.0.1:5000/;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question