snipt/salt/application/snipt.nginx.conf

85 lines
2.0 KiB
Plaintext

upstream backend_snipt {
server 127.0.0.1:8000;
}
{% if pillar.env_name != 'vagrant' %}
server {
listen 80;
server_name *.{{ pillar.hostname }};
if ($host ~* "^([^.]+(\.[^.]+)*)\.{{ pillar.hostname }}$"){
set $subd $1;
rewrite ^(.*)$ https://$subd.{{ pillar.hostname }}$1 permanent;
break;
}
}
server {
listen 80;
server_name {{ pillar.hostname }} www.{{ pillar.hostname }} beta.{{ pillar.hostname }};
rewrite ^(.*) https://{{ pillar.hostname }}$1 permanent;
}
server {
listen 443;
server_name www.{{ pillar.hostname }};
ssl on;
ssl_certificate /etc/certs/2013-dnsimple/{{ pillar.hostname }}.crt;
ssl_certificate_key /etc/certs/2013-dnsimple/{{ pillar.hostname }}.key;
rewrite ^(.*) https://{{ pillar.hostname }}$1 permanent;
}
server {
listen 443;
server_name {{ pillar.hostname }} *.{{ pillar.hostname }};
ssl on;
ssl_certificate /etc/certs/2013-dnsimple/{{ pillar.hostname }}.crt;
ssl_certificate_key /etc/certs/2013-dnsimple/{{ pillar.hostname }}.key;
location ~* /favicon.ico {
root /var/www/snipt/static/img/;
expires max;
}
location / {
rewrite_by_lua '
if string.find(ngx.var.host, "_") then
local newHost, n = ngx.re.gsub(ngx.var.host, "_", "-")
ngx.redirect(ngx.var.scheme .. "://" .. newHost .. ngx.var.uri)
end
';
proxy_pass http://backend_snipt;
proxy_set_header Host $host;
}
location /static/ {
alias /var/www/snipt/static/;
expires max;
}
location /public/feed/ {
rewrite ^/public/feed/$ https://{{ pillar.hostname }}/public/?rss permanent;
}
}
{% endif %}
server {
listen 80 default_server;
location ~* /favicon.ico {
root /var/www/snipt/static/img/;
expires max;
}
location / {
proxy_pass http://backend_snipt;
proxy_set_header Host $host;
}
{% if pillar.env_name != 'vagrant' %}
location /static/ {
alias /var/www/snipt/static/;
expires max;
}
{% endif %}
}