Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nginx configuration for Mac OS X with Homebrew, using sites-available directory.
mkdir -p /usr/local/etc/nginx/sites-available

File locations:

  • nginx.conf to /usr/local/etc/nginx/
  • default and default-ssl to /usr/local/etc/nginx/sites-available
    #STOP APACHE
    sudo apachectl stop

    #REPLACE PORTS
    sudo sed -i 's/8080/80g' /usr/local/etc/nginx/nginx.conf
    mkdir -p /usr/local/etc/nginx/sites-available

    wget https://gist.githubusercontent.com/kmassada/1ad1b0e1742139b8f3d5/raw/47763109f40a44a1baf43926c709bff83e9cee94/default -O  /usr/local/etc/nginx/sites-available/default
    wget https://gist.githubusercontent.com/kmassada/1ad1b0e1742139b8f3d5/raw/47763109f40a44a1baf43926c709bff83e9cee94/default-ssl -O  /usr/local/etc/nginx/sites-available/default-ssl

    sudo nginx

    #SETUP PROJECTS
    mkdir ~/Sites
    sudo mkdir -p /var/ && sudo ln -s ~/Sites /var/www


    SITE="test.com"
    mkdir -p ~/Sites/$SITE
    echo '<html><body><h2>'${SITE}'</h2></body></html>' >> ~/Sites/$SITE/index.html
    yes|cp  -f /usr/local/etc/nginx/sites-available/default /usr/local/etc/nginx/servers/$SITE
    sed -i "s/localhost/$SITE.build/g" /usr/local/etc/nginx/servers/$SITE
    sed -i "s/root_path/\/var\/www\/$SITE/g" /usr/local/etc/nginx/servers/$SITE

    sudo nginx -s reload
server {
listen 443;
server_name localhost;
ssl on;
ssl_certificate server.crt;
ssl_certificate_key server.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root root_path;
index index.html index.htm;
}
}
server {
listen 80;
server_name localhost;
#access_log logs/host.access.log main;
location / {
root root_path;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.