Skip to content

Magento 2 on nginx with another nginx as a proxy

I have a VM running ngnix with magento 2 . internally , my vm is resolved by :
marketplace.corp.mycloud.com

From the internet, it is resolved with :
marketplace.mycloud.com

Http is working fine so far. and I want to keep the 2 options for demo purposes and later for inspections..

However, HTTPS is not working and I have been puzzled by all comments..

So here is the content of my nginx file of My Magento VM :

    upstream fastcgi_backend {
    server   unix:/run/php/php7.2-fpm.sock;
    }

    server {
            server_name marketplace.corph.mouradcloud.com;
            index  index.php index.html index.htm;
            listen 80;
            client_max_body_size 100M;
            set $MAGE_ROOT /var/www/marketplace.corph.mouradcloud.com/;
            set $MAGE_MODE developer;
            access_log /var/log/nginx/marketplace.corph.mouradcloud.com-access.log;
            error_log /var/log/nginx/marketplace.corph.mouradcloud.com-error.log;
            include /var/www/marketplace.corph.mouradcloud.com/nginx.conf.sample;
            }

Now here is the content of my reverse proxy nginx configuration :

        upstream marketplaceserver {
            server marketplace.corph.mouradcloud.com;
        }

        server {
        listen 80;
        listen 443;
        server_name marketplace.mouradcloud.com;
        ssl_certificate /XXXX/XXXX/XXXX/marketplace.mouradcloud.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /XXXX/XXXX/XXXX/marketplace.mouradcloud.com/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

                location / {
                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_pass http://marketplaceserver;
                }


        }

The target is this one :

enter image description here

I have been switching configurations but I was not able to get it work, ideally, I would like to keep all configuration to the frontend proxy and not touch the magento configurations..

Any clue ?