A
A
Alexander Odintsov2016-08-04 18:14:45
Nginx
Alexander Odintsov, 2016-08-04 18:14:45

How to configure nginx to load css via proxy_pass?

We needed to make it so that when accessing a specific folder of the site, information from our other project was loaded. It turned out to be quite simple

location ^~ /domain-lp/ {
        proxy_pass http://domain.ru/lp/;
    }

After some time, colleagues needed a similar task, and it seemed that this code would work)
location ^~ /domain-sm/ {
        proxy_pass http://domain.ru/sm/;
    }

But in the second case, css and js files are not loaded, but only html is loaded.
The difference is that in the first case there are one-page landings in domain.ru/lp and all css and js are inside the folder.
And in the second case, domain.ru/sm site pages are managed by cms and all paths to css and js go from the host.
I rummaged through half the Internet and eventually settled on such a config, which still does not work.
location ^~ /domain-sm/ {
        proxy_pass http://domain.ru/sm/;
        proxy_set_header Host domain.ru;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

Issue resolved.
On the original page, you need to move the tag <base>before adding css

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question