#Setting up Nginx on Your Local System ###by Keith Rosenberg
##Step 1 - Homebrew The first thing to do, if you're on a Mac, is to install homebrew from http://mxcl.github.io/homebrew/
The command to type into terminal to install homebrew is:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Following the installation of homebrew, type
brew cleanup
and then
brew doctor
Running brew doctor will inform you if you have any problems with your install or your machine in general. If you run into troubles, Stack Overflow is your best friend.
I can't help you :'(
##Step 2 - nginx With homebrew installed, you can run (note: without sudo - do not run 'sudo brew' - it's evil)
brew install nginx
directly following install, run
sudo nginx
this will start nginx on port 8080. Open your web browser and go to http://localhost:8080
If this works, run
sudo nginx -s stop
to stop nginx.
##Step 3 - Set up nginx.conf Your nginx.conf file lives at
/usr/local/etc/nginx/nginx.conf
The absolute first thing you should do is make a backup copy of this file in case you royally destroy everything:
mv /usr/local/etc/nginx/nginx.conf /usr/local/etc/nginx/nginx.conf.bak && cp /usr/local/etc/nginx/nginx.conf.bak /usr/local/etc/nginx/nginx.conf
you now have a fresh copy of the nginx.conf file to bastardize, and a backup copy in case you get in too deep.
##Step 4 - Modularizing Nginx for Serving Multiple Local Websites The last thing you want to do is create a directory where you can store individual site nginx.conf files. At the bottom of your nginx.conf file, before your last closing bracket, you should include the following line:
http {
# ... ...
# ... ... nginx stuff
# ... ...
# include all server conf files
include conf.d/*.conf;
}
Then, make a conf.d directory in your nginx folder:
mkdir /usr/local/etc/nginx/conf.d
and now whenever you create a new server, just place them into your conf.d directory:
vim /usr/local/etc/nginx/conf.d/myWebSite.conf
you can then put a specific server config into that file like so:
server {
listen 8080;
server_name mywebsite.local.com;
location / {
root /Users/myusername/Desktop/Projects/mywebsite/public/;
index index.html index.htm;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
####listen The port number you want nginx to listen on for this site
####server_name Points to a domain configured in your Mac OSX host file (note: be sure to edit with "sudo", as super user):
> sudo vim /private/etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
# mywebsite
127.0.0.1 mywebsite.local.com
####location Sets up a route and describes where it should point. The root sub-attribute should be a path from / (root) to your project on your local machine.
nice and clear here. I had ran into a case where i had like five nginx servers running in apps like xcode, the Apple Server was hijacking my pages when i tried localhost:XXXXX for whichever ports i tried, so this help. left with trying
brew services start nginx