Mac OS X System Installation Nginx

Keywords: Nginx OpenSSL brew sudo

1. Preparations

When installing Nginx, because some modules of Nginx need to rely on other third-party libraries, such as pcre library (supporting rewrite module), zlib library (supporting gzip module) and openssl library (supporting ssl module), it is recommended to install with the help of Homebrew tool.

Homebrew Reference: HomeBrew uses

2. Installing Nginx

After installing Homebrew, the terminal executes:

brew search nginx
brew install nginx

During installation, the terminal output information:

XXXdeMacBook-Pro:~ XXX$ brew install nginx
Updating Homebrew...
==> Installing dependencies for nginx: pcre, openssl@1.1
==> Installing nginx dependency: pcre
==> Downloading https://homebrew.bintray.com/bottles/pcre-8.39.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring pcre-8.39.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/pcre/8.39: 203 files, 5.4M
==> Installing nginx dependency: openssl@1.1
==> Downloading https://homebrew.bintray.com/bottles/openssl@1.1-1.1.0d.sierra.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring openssl@1.1-1.1.0d.sierra.bottle.1.tar.gz
==> Using the sandbox
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs

and run
  /usr/local/opt/openssl@1.1/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local.

This is an alternate version of another formula.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/openssl@1.1/lib
    CPPFLAGS: -I/usr/local/opt/openssl@1.1/include

==> Summary
🍺  /usr/local/Cellar/openssl@1.1/1.1.0d: 6,303 files, 15.4M
==> Installing nginx 
==> Downloading https://homebrew.bintray.com/bottles/nginx-1.10.3.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring nginx-1.10.3.sierra.bottle.tar.gz
==> Caveats
Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

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

To have launchd start nginx now and restart at login:
  brew services start nginx
Or, if you don't want/need a background service you can just run:
  nginx
==> Summary
🍺  /usr/local/Cellar/nginx/1.10.3: 8 files, 980.9K

After installation, you can see some configuration paths in the terminal output information:

  • / usr/local/etc/nginx/nginx.conf (configuration file path)
  • / usr/local/var/www (server default path)
  • / usr/local/Cellar/nginx/1.10.3 (installation path)

Where the log directory:

  • /usr/local/var/log/nginx

After running nginx, look at the directory of the Nginx service main process PID:

  • /usr/local/var/run/nginx.pid

3. Start Nginx

The terminal can start by inputting nginx command:

nginx

Visit localhost:8080 and find that the welcome page of nginx has appeared.

4. Common commands

Commonly used instructions are:

  • Nginx-V View Version and Configuration File Address
  • Nginx-v View Version
  • Nginx-c filename specifies the configuration file
  • Nginx-h help

Reload Configuration | Restart | Stop | Exit nginx

nginx -s reload|reopen|stop|quit

Open nginx

sudo nginx

Test configuration for grammatical errors

nginx -t

Posted by robertf on Fri, 05 Apr 2019 15:18:31 -0700