/ Nginx

Setting up NGINX on Mac OSX

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 [email protected]: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