cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with base-url when using NGINX Reverse-Proxy and NGINX inside a PHP Docker Container

Problem with base-url when using NGINX Reverse-Proxy and NGINX inside a PHP Docker Container

I have the following code on my NGINX Reverse-Proxy (running on the host):

upstream magento235 {
    server localhost:10080;
}

upstream magento241 {
    server localhost:10090;
}

server {
    server_name my_domain;

    client_max_body_size 32M;

    location /magento235 {
        proxy_pass http://magento235/;
        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 https;
        proxy_set_header X-Forwarded-Port 443;
        proxy_set_header Host $host;
        proxy_set_header Ssl-Offloaded 1;
        proxy_set_header DBG-SSL 1;
        fastcgi_param HTTPS on;

        proxy_buffer_size 128k;
        proxy_buffers 4 256k;
        proxy_busy_buffers_size 256k;
    }


    location /magento241 {
        proxy_pass http://magento241/;
        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 https;
        proxy_set_header X-Forwarded-Port 443;
        proxy_set_header Host $host;
        proxy_set_header Ssl-Offloaded 1;
        proxy_set_header DBG-SSL 1;
        fastcgi_param HTTPS on;

        proxy_buffer_size 128k;
        proxy_buffers 4 256k;
        proxy_busy_buffers_size 256k;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/my_domain/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/my_domain/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

And then inside my Docker container, that is run an imaged based on Alpine with php 7.3 installed I have the following NGINX configuration:

upstream fastcgi_backend {
    # use tcp connection
    # server  127.0.0.1:9000;
    # or socket
    #server   unix:/var/run/php5-fpm.sock;
    server 127.0.0.1:9000;
}

server {
    listen 8088;
    server_name _;

    set $MAGE_ROOT /var/www/html;
    client_max_body_size 32M;

    real_ip_header X-Forwarded-For;
    set_real_ip_from 172.18.0.0/24;
    set_real_ip_from 172.17.0.0/24;

    include /etc/nginx/conf.d/magento2;
}

My base_url is set to the following:

 

UPDATE core_config_data SET value="https://my.domain/" WHERE path = 'web/unsecure/base_url' or path = 'web/secure/base_url';
UPDATE core_config_data SET value=NULL WHERE path = 'web/unsecure/base_static_url' OR path = 'web/unsecure/base_media_url' OR path = 'web/secure/base_static_url' or path = 'web/secure/base_media_url';

My problem here is that when I acced my.domain/magento235 it basically throws me the error ERR_TOO_MANY_REDIRECTIONS or the reverse proxy accesses the magento235 folder and I don't have that folder.

The idea is to have 2 installations running on the same server and have the reverse proxy use locations to access them.

Is there anyone that can help me with the correct configuration? Thank you.