server {
    server_name cheryksa.com www.cheryksa.com;

    client_max_body_size 100M;

    error_page 503 @custom_503;

    gzip on;
    gzip_types application/font-woff application/font-woff2 text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_min_length 1000;
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;

    location @custom_503 {
        default_type text/plain;
        return 503 "Service Unavailable: The environment is not deployed yet, please try again later.";
    }

    location ~ ^/(logs|health) {
        set $root_path /home/ubuntu/chery/event-proxy/master;
        if (!-d $root_path) {
            return 503;
        }

        proxy_pass http://chery-event-proxy_master;

        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $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;
        proxy_set_header Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_pass_request_headers on;

    }

    location / {
        set $root_path /home/ubuntu/chery/frontend/master;
        if (!-d $root_path) {
            return 503;
        }

        more_set_headers 'Access-Control-Allow-Origin: $http_origin';
        more_set_headers 'Access-Control-Allow-Methods: GET,POST,PUT,PATCH,DELETE,OPTIONS';
        more_set_headers 'Access-Control-Allow-Credentials:true';
        more_set_headers 'Access-Control-Allow-Headers:Authorization,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

        proxy_pass http://chery-frontend_master;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    location /_next/static/ {
        alias /home/ubuntu/chery/frontend/master/current/.next/static/;
        expires 1y;
        access_log off;
        add_header Access-Control-Allow-Origin "*";
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/cheryksa.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/cheryksa.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


}

server {
    if ($host = www.cheryksa.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = cheryksa.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    server_name cheryksa.com www.cheryksa.com;


    listen 80;
    return 404; # managed by Certbot




}
