Skip to content

Instantly share code, notes, and snippets.

@muratcorlu
Created November 3, 2017 23:42
Show Gist options
  • Save muratcorlu/bae35db86429684f018d4c9f0b6123ca to your computer and use it in GitHub Desktop.
Save muratcorlu/bae35db86429684f018d4c9f0b6123ca to your computer and use it in GitHub Desktop.
Serve static websites by dynamically mapping domain names and folders with nginx
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/${host}/public;
index index.html;
server_name _;
gzip on;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.html;
}
# 404 if a file is requested (so the main app isn't served)
location ~ ^.+\..+$ {
try_files $uri =404;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment