Skip to content

Instantly share code, notes, and snippets.

@BenHall
Created March 3, 2014 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenHall/9316648 to your computer and use it in GitHub Desktop.
Save BenHall/9316648 to your computer and use it in GitHub Desktop.
nginx config file
upstream domain {
server 127.0.0.1:3001;
}
server {
listen 80;
server_name domain.io another.domain.io;
return 301 http://main.domain.com$request_uri;
}
server {
listen 80;
server_name main.domain.com;
access_log /var/log/nginx/domain-com.log;
location ~ ^/(images|javascript|javascripts|stylesheets|fonts|robot.txt)/ {
root /var/www/domain/public;
expires 1d;
}
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://domain;
proxy_redirect off;
}
}
@BenHall
Copy link
Author

BenHall commented Sep 4, 2014

Forces redirect to main.domain.com, for example entering non-www URL or an alternative ending.

Static files are served directly from the directory the node app lives in. Other requests are sent to port 3001 running on the same box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment