Minimalist nginx vhost template example
Sometimes make sense to put small and understandable template. I don't see any point to use separated 80 and 443 vhosts if you need only 443, and 80 needed only for redirect.
{% set domains = [domain] + alias|default([]) -%}
server {
listen 80;
listen 443 ssl http2;
server_name {{ domains|join(' ') }};
if ($scheme = http) {
return 301 https://$host$request_uri;
}
if ($host ~* ^www\.(.*)$) {
return 301 $scheme://$1$request_uri;
}
ssl_certificate /etc/nginx/crt/{{ domain }}.crt;
ssl_certificate_key /etc/nginx/crt/{{ domain }}.key;
root /var/www/{{ domain }}/;
index index.html index.htm;
access_log /var/log/nginx/{{ domain }}_access.log everything;
error_log /var/log/nginx/{{ domain }}_error.log;
location / {
...
}
}
Comments
Post a Comment