Skip to content

Instantly share code, notes, and snippets.

@elsassph
Last active August 30, 2016 07:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elsassph/15d3aa593b01526481a3a0ca146e7e08 to your computer and use it in GitHub Desktop.
Save elsassph/15d3aa593b01526481a3a0ca146e7e08 to your computer and use it in GitHub Desktop.
Nginx single-page app local dev server config

Easy single-page app dev using nginx

If you're using only nginx (no Apache thx) and want to serve your projects using a local dev domain.

Install nginx

brew install nginx

Or download/unzip for Win: http://nginx.org/en/docs/windows.html

Configure nginx

Edit /usr/local/etc/nginx/nginx.conf or C:\nginx\confg\nginx.conf, following the sample below.

Start/reload nginx

sudo nginx
sudo nginx -s reload
sudo nginx -s quit

Configure hosts

Edit /etc/hosts/ or C:\Windows\System32\drivers\etc\hosts to add your dev domains.

127.0.0.1   dev.project1.com
127.0.0.1   dev.project2.com
[...]
http {
[...]
server {
listen 80;
[...]
}
# project1
server {
server_name dev.project1.com;
try_files $uri /index.html;
root /path/to/project1/www;
}
# project2
server {
server_name dev.project2.com;
try_files $uri /index.html;
root /path/to/project2/www;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment