Setting up NGINX on Mac OSX

. 2 min read

Heavily borrowed from: Nginx configuration for Mac OS X with Homebrew, using sites-enabled directory.

Install nginx

brew install nginx
cd /usr/local/etc/nginx/

git clone git@bitbucket.org:fountainhead/nginx-sites-available sites-available

wget "https://gist.githubusercontent.com/jimothyGator/5436538/raw/9e0b6674a6b8c50589ea4d811b845545a776ca16/default-ssl.conf"
wget "https://gist.githubusercontent.com/jimothyGator/5436538/raw/9e0b6674a6b8c50589ea4d811b845545a776ca16/default.conf"

mkdir -p /usr/local/etc/nginx/sites-enabled
cd /usr/local/etc/nginx/sites-enabled


ln -s ../sites-available/default.conf
ln -s ../sites-available/default-ssl.conf

cd /usr/local/etc/nginx/
rm nginx.conf
wget "https://gist.githubusercontent.com/jimothyGator/5436538/raw/9e0b6674a6b8c50589ea4d811b845545a776ca16/nginx.conf"

# Create log directory
sudo mkdir -p /Library/Logs/nginx/

For enabling a site:

cd /usr/local/etc/nginx/sites-enabled
ln -s ../sites-available/santoshsrinivas.dvp

Start nginx:

# Test out nginx
sudo nginx -t

sudo nginx -s stop

sudo nginx -s stop && sudo nginx

# Start nginx
sudo nginx -s reload

Update /etc/hosts file:

127.0.0.1 xeon.santoshsrinivas.dvp

My site config file:

server {
    server_name xeon.santoshsrinivas.dvp; # Replace with your domain
    access_log /var/log/xeon_ss_dvp_acc.log;
    error_log /var/log/shiny_ss_dvp_err.log;

    location / {
        proxy_pass http://127.0.0.1:9000;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffering off;
    }
}

My nginx.conf

#user  nobody;
worker_processes  1;

error_log  /Library/Logs/nginx/error.log;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /Library/Logs/nginx/access.log  main;

    sendfile        on;

    keepalive_timeout  65;

    index index.html index.php;
    
    upstream www-upstream-pool{
        server unix:/tmp/php-fpm.sock;
    }

    include /usr/local/etc/nginx/sites-enabled/*; 
}

UPDATES:

Despite following the above instructions, I was again caught with error issues while setting up my new Catalina OS.

The resolution steps after troubleshooting the problems were:

Make sure the last line in the above nginx.conf is updated to:

include /usr/local/etc/nginx/sites-enabled/*.*; 

Note ... then *.*

Next, this was a REAL issue, I did everything perfectly but STILL the enabled was not getting picked up!!!

As mentioned here (https://stackoverflow.com/a/53528685), I needed to add listen [::]:80; to bind the site to IPv6 and my PC was on an IPv6 connection

Below is the exact site config:

server {
    server_name www.themescope.dvp; # Replace with your domain

    listen 80;
    listen [::]:80;

    access_log /var/log/themescope_dvp_acc.log;
    error_log /var/log/themescope_dvp_err.log;

    location / {
        proxy_pass http://127.0.0.1:8050;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffering off;
    }
}

Also, not to forget .. my /etc/hosts/ file is:

##
# 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
127.0.0.1 themescope.dvp
127.0.0.1 www.themescope.dvp

255.255.255.255	broadcasthost
::1             localhost

Tags

AWS Analytics Antifragile Apache Spark Apple Apps Arbitrage Automation Awesome BBMP Bangalore Black Swan Bonds Boonex Bootstrap Brokerage Charges CFPB CMS CSS Calypso Camelot Capital Markets Charts Chirp Choropleth Chrome Code Igniter Collections Containerization Converters Cycling DalalBeat Data Analytics Data Journalism Data Mining Data Munging Data Privacy Data Science Databases Debt Design Design Stock DesignStock Diet Django Docker Document Processing Dropbox Electron Electronics Entertainment Entrepreneurship Exercise FFMPEG Facebook Finance Fire TV Stick Fitness Forerunner From-The-News Fun Futures Gaana Garmin General Geocoding Getting Started Ghost Google APIs GraphicsMagick HHVM HTTPS Hackathon Hacks Hardware Health House Keeping Housing IBM BlueMix IBrokers IPinfo Ideas Image Conversion Image Processing Infographics Interactive Brokers Internet Investing IoT Legal Lets Encrypt Mac Machine Learning Mailbox app Mapbox Markdown Marketing Meteor Mockups MongoDB Mortgages Movies Music MyPad MySQL Nativefier Nature Netflix Newsletters Nginx Node.js Notes OCR OSX Open Source OpenCPU Options PDF PHP Pebble Peloton Personal Photography Picture Platforms Plex Portable Apps Productivity Property Tax PyroCMS Quantitative Finance R-Project Random Raspberry Pi Research Resources Reticulate Robot S3 SQLite STT Scraping Security Server Shell Shiny Side Project Sikuli Speech Recognition Spider Pro Spinning Spotify Startup Resources Startups Strategy Sublime Text System Monitoring Tax Terminal Tips To Do Tools Torrent Trading Trends Troubleshooting USElection2016 Ubuntu Unix Valuations Video Conversion Visualization Wagtail Wearables Weekend Fun WhatsApp Wordpress anaconda annie bash catalina cv2 daily coding dailycoding data.table debugging devtools downloader e-Signatures ggplot git go google maps hat-tip iOS iPad iPhone iTunes javascript jupyter logging macos numpy opencv optionality plotly python rstats videos youtube