Created
April 22, 2019 16:20
-
-
Save ziazon/7d21d40cb62295241b1b3a1b32624c3c to your computer and use it in GitHub Desktop.
nginx for sub domain based reverse proxying to static resources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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