nginx Notes

OSX Installation

1
brew install nginx

The nginx docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080.

nginx will load all files in /usr/local/etc/nginx/servers/.

To have launchd start nginx now and restart at login:

1
brew services start nginx
If you don't want/need a background service you can just run:
1
nginx

Raspian Installation

1
sudo apt-get install nginx

The nginx docroot is: /usr/local/var/www

The default port has been set in /etc/nginx/nginx.conf to 8080.

nginx will load all .conf files in /etc/nginx/conf.d/.

Configuration

Example of nginx config file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
  server {
    listen 8001;
    server_name _;

    access_log  /tmp/access.log;
    error_log  /tmp/errors.log;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_redirect     off;

        rewrite ^/$ /image?delay=0.25 permanent;

        proxy_set_header   Host                 $host;
        proxy_set_header   X-Real-IP            $remote_addr;
        proxy_set_header   X-Forwarded-For      $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto    $scheme;
    }
  }

After editing a config file, restart nginx with:

1
nginx -s reload