Skip to content

Instantly share code, notes, and snippets.

@schollz
Last active January 8, 2016 18:26
Show Gist options
  • Save schollz/95c44f685ad6d79ef66d to your computer and use it in GitHub Desktop.
Save schollz/95c44f685ad6d79ef66d to your computer and use it in GitHub Desktop.

To get started with NGINX, first install:

sudo apt-get install nginx

Now you just need to setup a reverse proxy. Say you have a name for your server, example.com but your actual address is ifj.ckd.acj.djx:1239. To make people see that your website is example.com first you need to go to your name service (Namecheap or other) and make sure you have the A field set to ifj.ckd.acj.djx. Do not include the port number here.

Now, on your server, make a new NGINX block

  sudo vim /etc/nginx/sites-available/example.com

And copy and paste the following into this file:

server {
	# SERVER BLOCK FOR %(appname)s
	listen   80; ## listen for ipv4; this line is default and implied
	root /dir/where/files/are;
	access_log /etc/nginx/logs/access-example.com.log;
	error_log /etc/nginx/logs/error-example.com.log;
	server_name example.com www.example.com;
	location / {
		proxy_pass http://ifj.ckd.acj.djx:1239`;
		proxy_redirect off;
		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;
	}
}

Make sure to change /dir/where/files/are to the directory where your files are, although this really isn't nessecary if you're just using reverse proxy as its only used to serve static files (and you have no static file settings). But include it anyways, as I don't know what happens if you don't.

Now, you need to make a link to add this block to your server:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com

And then reload and restart nginx:

sudo service nginx reload
sudo service nginx restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment