Forked from netpoetica/Setting up Nginx on Your Local System.md
Created
December 28, 2018 19:33
-
-
Save devwork-g/3b47d955d3a202d3a3340c3b0ab8b72e to your computer and use it in GitHub Desktop.
Revisions
-
Keith Rosenberg revised this gist
Jan 22, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ The first thing to do, if you're on a Mac, is to install homebrew from http://mx 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 -
Keith Rosenberg revised this gist
Jun 27, 2013 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -110,10 +110,10 @@ server { ``` ### Breaking Down a Server Configuration ####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 @@ -130,5 +130,5 @@ Points to a domain configured in your Mac OSX host file (note: be sure to edit w # 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. -
Keith Rosenberg created this gist
Jun 27, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,134 @@ #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.github.com/mxcl/homebrew/go)" ```` 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. #### But I'm on Windows 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: ````nginx 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; } } ``` ### Breaking Down a Server Configuration #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.