how to properly configure location in nginx proxy pass

There is a blog located on a separate IP, on it nginx is raised to 443

server {
    listen 443 ssl default_server;
    ssl_certificate /etc/nginx/ssl/cert.crt;
    ssl_certificate_key /etc/nginx/ssl/cert.key;

    ssl_session_cache builtin:1000 shared:SSL:10m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;


    index index.php index.html;
    server_name example.com;

    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    root /app/wp;

    location ~ /\. {
        deny all; # запрет для скрытых файлов
    }

    location ~* /(?:uploads|files)/.*\.php$ {
        deny all; # запрет для загруженных скриптов
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

You must make sure that the path /blog on the main site leads to this resource

The following options do not work:

Only the main{[12] is processed]}
location  ~ ^/blog/(.*)$ {
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $http_host;

            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forward-Proto http;
            proxy_set_header X-Nginx-Proxy true;
            proxy_pass https://127.0.0.1/$1$is_args$args;
        }

The request goes only to the root directory /

Static gets 404 and does not reach the source

location  /blog/ {
    proxy_pass https://127.0.0.1/;
}

Get params{[12] are lost]}
location  ~ ^/blog {
        proxy_pass https://52.51.81.133;
    }

Categories and subcategories are not proxied, tried adding subcategories to a separate location for example:

location  ~ ^/blog/tag/(.*)$ {
    proxy_pass https://127.0.0.1/tag/$1$is_args$args;
}
location  ~ ^/blog/category/(.*)$ {
    proxy_pass https://127.0.0.1/category/$1$is_args$args;
}

BUT!! there are still ways with articles like: / blog/article-1 /blog/article-2/ and what to do with them is not quite clear

Author: Alexey Kapitonov, 2019-03-06

1 answers

That's right:

location  ~ ^/blog {
    proxy_pass https://127.0.0.1;
    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
}

With this form, the regular expression will process all uris with /blog and give $path in an uncut form to the proxy along with the get parameters

 3
Author: Alexey Kapitonov, 2019-03-11 11:10:28