access_log /var/log/nginx/{{ hostname }}.access.log;
error_log /var/log/nginx/{{ hostname }}.error.log;

server {
    server_name {{ hostname }};

    location ~ \.\. {
        return 403;
    }

    location / {
        proxy_pass http://localhost:{{ port }};
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location /static {
        autoindex on;
        alias /srv/www/{{ hostname }}/static/;
    }

    location /media {
        autoindex on;
        alias /srv/www/{{ hostname }}/media;
    }

    proxy_read_timeout 300s;
    proxy_connect_timeout 300s;

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

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/lyprox.org/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/lyprox.org/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 {
    # managed by Certbot
    if ($host = {{ hostname }}) {
        return 301 https://$host$request_uri;
    }
    return 404; # managed by Certbot
}
