Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rake-sh/af9c2cb8f9eb1dd7b39dd7d3de4299c6 to your computer and use it in GitHub Desktop.
Save rake-sh/af9c2cb8f9eb1dd7b39dd7d3de4299c6 to your computer and use it in GitHub Desktop.

Revisions

  1. Keith Rosenberg revised this gist Jan 22, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Setting up Nginx on Your Local System.md
    Original 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.github.com/mxcl/homebrew/go)"
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    ````

    Following the installation of homebrew, type
  2. Keith Rosenberg revised this gist Jun 27, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions Setting up Nginx on Your Local System.md
    Original file line number Diff line number Diff line change
    @@ -110,10 +110,10 @@ server {
    ```
    ### Breaking Down a Server Configuration
    #listen
    ####listen
    The port number you want nginx to listen on for this site
    #server_name
    ####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
    ####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.
  3. Keith Rosenberg created this gist Jun 27, 2013.
    134 changes: 134 additions & 0 deletions Setting up Nginx on Your Local System.md
    Original 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.