server {
    listen 80;
    listen [::]:80;
    server_name royal-pop-accessory.com www.royal-pop-accessory.com;

    return 308 https://$host$request_uri;
}

server {
    listen 80;
    listen [::]:80;
    server_name api.royal-pop-accessory.com;

    return 308 https://$host$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name royal-pop-accessory.com www.royal-pop-accessory.com;

    root /usr/share/nginx/html;
    index index.html;

    ssl_certificate /etc/nginx/certs/origin.crt;
    ssl_certificate_key /etc/nginx/certs/origin.key;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 1d;

    gzip on;
    gzip_types text/plain text/css application/json application/javascript application/xml+rss application/xml image/svg+xml;

    add_header X-Content-Type-Options nosniff always;
    add_header Referrer-Policy strict-origin-when-cross-origin always;
    add_header X-Frame-Options SAMEORIGIN always;

    location = /buy {
        return 308 $scheme://$host/buy/;
    }

    location = /details {
        return 308 $scheme://$host/details/;
    }

    location = /checkout {
        return 308 $scheme://$host/checkout/;
    }

    location = /client {
        return 308 $scheme://$host/client/;
    }

    location = /client/orders {
        return 308 $scheme://$host/client/orders/;
    }

    location = /client/stock {
        return 308 $scheme://$host/client/stock/;
    }

    location = /thank-you {
        return 308 $scheme://$host/thank-you/;
    }

    location / {
        try_files $uri $uri/ =404;
    }
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name api.royal-pop-accessory.com;

    ssl_certificate /etc/nginx/certs/origin.crt;
    ssl_certificate_key /etc/nginx/certs/origin.key;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 1d;

    gzip on;
    gzip_types text/plain text/css application/json application/javascript application/xml+rss application/xml image/svg+xml;

    add_header X-Content-Type-Options nosniff always;
    add_header Referrer-Policy strict-origin-when-cross-origin always;
    add_header X-Frame-Options SAMEORIGIN always;

    client_max_body_size 1m;

    location / {
        proxy_pass http://api:8081;
        proxy_http_version 1.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;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
