P
P
plavsk2021-01-28 00:17:37
Nginx
plavsk, 2021-01-28 00:17:37

Nginx in reverse proxy mode need a site to slide into?

We have several backs and now they decided to collect them under one domain name.
When shifting, location works partially, the problem is that it does not load styles, and it looks for styles from the root and not from the shift.
nginx

location config ~* ^/a/(.*)$ {
if ($http_cookie ~* ".+" ) {
set $do_not_cache 1;
}
proxy_cache_bypass $do_not_cache;
if ($request_method !~ ^(OPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT|PROPFIND|PROPPATCH|MKCOL|COPY|MOVE|LOCK|UNLOCK|VERSION-CONTROL|REPORT|CHECKOUT|CHECKIN|UNCHECKOUT| MKWORKSPACE|UPDATE|LABEL|MERGE|BASELINE-CONTROL|MKACTIVITY|ORDERPATCH|ACL|SEARCH|MKCALENDAR|PATCH)$) {
return 405;
}

proxy_set_header Host $host
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Connection "";

proxy_ignore_headers "Cache-Control" "Expires";
proxy_cache cache;
proxy_cache_valid 1d;
proxy_cache_valid 404 502 503 1m;

rewrite ^/a/(.*)$ /$1 break;

proxy_http_version 1.1;
proxy_read_timeout 1800s;
proxy_send_timeout 1800s;

client_max_body_size 0;
proxy_buffering on;
proxy_request_buffering off;
proxy_redirect off;
proxy_pass 'back4 ';

That is, I shift it from the root to the /a/ directive, the site is loaded without styles, I look through the browser console, they are searched from the root and not from /a/
Help someone know how to fix this

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fenrir89, 2021-01-28
@Fenrir89

It may be easier to make it in the form of several pages of the form www.asd.ry/y, www.asd.ry/z, and set up different locations for them with a different root

I
Ivan Koryukov, 2021-01-28
@MadridianFox

As already written in the comments, where the application decides to look for styles, and for good it is necessary to make the paths for loading statics customizable in each back.
However, if all the backs are on the same machine, you can substitute a crutch.
You can create a special location, even several, which will look for the requested file first in one folder, then in another, then in a third.

location ~* \.(css|js)$ {
    root /path/to/back1;
    try_files $uri @back2;
}

location @back2 {
   root /path/to/back2;
   try_files $uri @back3;
}

location @back3 {
   root /path/to/back3;
   try_files $uri =404;
}

If one of the backs is not on the same machine, then you can put it at the end and proxy it:
location @back3 {
   proxy_pass http://external-service.com;
}

Also, you can consider the option with conditions that look at the headers of the request, well, there is some kind of referer or origin, and depending on this, they proxy to one or another back.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question