Skip to content

Instantly share code, notes, and snippets.

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
    sudo apachectl stop

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

    wget -O  /usr/local/etc/nginx/sites-available/default
    wget -O  /usr/local/etc/nginx/sites-available/default-ssl

    sudo nginx

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

    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/$" /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