R
R
Rollex2020-08-15 05:57:53
Nginx
Rollex, 2020-08-15 05:57:53

Proxy_pass in Nginx - how to work with variables?

You need to receive a file via a link from another domain
https://site1.ru/link/pDK9VJacsrb9bway?no=2 - this is the main site, but I would like to receive a file via a mirror site https://site2.ru/link/pDK9VJacsrb9bway?no= 2

Main site config:

server {
        root /var/www/site1.ru/public;
        index index.php index.html;
        server_name site1.ru;

        location / {
            try_files $uri /index.php$is_args$args;
        }

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        }


Mirror site config:

server {
        index index.php index.html;
        server_name site2.ru;

        location / {
        root /var/www/site2.ru;
        }

location /link/ {
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        }

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

proxy_pass https://site1.ru:443/;
}

With this config, api https://site2.ru/api/node3?access_token=nyV0Wv142G... works fine (thanks to dodo512 )
but the link to the file https://site2.ru/link/pDK9VJacsrb9bway?no=2 gives 404 mistake

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-08-15
@Rollex

nginx.org/en/docs/http/ngx_http_proxy_module.html#...
If the proxy_pass directive is specified with a URI, then when the request is sent to the server, the part of the normalized request URI corresponding to location is replaced by the URI specified in the directive:

location /link/ {
    proxy_pass https://site1.ru/;

Here /link/it will be replaced by /as a result https://site1.ru/pDK9VJacsrb9bway?no=2
If the proxy_pass directive is specified without a URI, then when processing the initial request, the request URI is transmitted to the server in the same form in which it was sent by the client.
location /link/ {
    proxy_pass https://site1.ru;

And here's what needs to be removed.proxy_set_header Host $host;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question