upstream innerdjango {
    server backend:8000;
}

upstream innerreact {
    server frontend:3000;
}


server {
    listen 80;
    listen [::]:80;

    server_name api.portal.acconcept.ru www.api.portal.acconcept.ru;
    server_tokens off;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        return 301 https://api.portal.acconcept.ru$request_uri;
    }
}

server {
    listen 80;
    listen [::]:80;

    server_name portal.acconcept.ru www.portal.acconcept.ru;
    server_tokens off;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        return 301 https://portal.acconcept.ru$request_uri;
    }
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    ssl_certificate /etc/nginx/ssl/live/api.portal.acconcept.ru/fullchain.pem;
    ssl_certificate_key /etc/nginx/ssl/live/api.portal.acconcept.ru/privkey.pem;
    server_name api.portal.acconcept.ru www.api.portal.acconcept.ru;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://innerdjango;
        proxy_redirect default;
    }
    location /static/ {
        alias /var/www/static/;
    }
    location /media/ {
        alias /var/www/media/;
   }
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    ssl_certificate /etc/nginx/ssl/live/portal.acconcept.ru/fullchain.pem;
    ssl_certificate_key /etc/nginx/ssl/live/portal.acconcept.ru/privkey.pem;
    server_name portal.acconcept.ru www.portal.acconcept.ru;
    
    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://innerreact;
        proxy_redirect default;
    }
}