Skip to content

Instantly share code, notes, and snippets.

@ziazon
Created April 22, 2019 16:20
Show Gist options
  • Save ziazon/7d21d40cb62295241b1b3a1b32624c3c to your computer and use it in GitHub Desktop.
Save ziazon/7d21d40cb62295241b1b3a1b32624c3c to your computer and use it in GitHub Desktop.
nginx for sub domain based reverse proxying to static resources
server {
listen 80;
server_name ~^(?<subdomain>.+)\.(.*)$;
root /usr/share/nginx/html/dist;
location ~ ^.+\..+$ {
try_files $uri @assets;
}
location / {
try_files $uri $uri/ @rewrites;
}
location @rewrites {
rewrite ^(.+)$ /index.html last;
}
location @assets {
# note that this assumes you store your env specific files in dedicated folders named by their subdomain.
rewrite ^/(.+)$ /cdn-path/$subdomain/$1 break;
resolver 8.8.8.8;
proxy_hide_header ETag;
proxy_hide_header x-amz-id-2;
proxy_hide_header x-amz-request-id;
proxy_intercept_errors on;
proxy_pass https://baseurl-of-cdn;
}
sendfile off;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment