With little tweaking, it is possible to install the NGINX web server on macOS. This guide first explains how to get NGINX running, and then how to set up the file structure so that it's identical to the Linux-based version.
How to install Nginx on Mac OS? Incase if your system didnot recongize this command, then install homebrew first by running below command and rerun above command once again. $ brew install nginx Installing dependencies for nginx: pcre, openssl Installing nginx dependency: pcre Downloading.
A little housekeeping
- How to Install Nginx on MacOS Introduction. Nginx is a web server which can also be used as a HTTP cache, load balancer and reverse proxy.This was first created by Igor Sysoev and released in 2004 under the terms of BSD like license. In this tutorial, we will learn the steps involved in the installation of Nginx.
- 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.1: 7 files, 972.3K.
- Go back to the operating system / installation method selection menu. Table of contents. Step 1: install Passenger package. Step 2: enable the Passenger Nginx module and restart Nginx.
- Installing NGINX on Mac. There are following steps to install the Nginx on Mac OS: Step 1: Download Homebrew. To install the Nginx on Mac OS, Homebrew must be installed on the system. Homebrew is a package manager for Mac operating system that allows us to install various Unix applications easily.
Before we install Nginx, we need to make sure that no other web server is running on macOS. To do this, we’ll stop Apache:
NOTE If Apache isn’t installed, this will obviously do nothing.
If you don't have it, install Homebrew
To install Nginx on macOS, we will need Homebrew. If you have not yet installed Homebrew, please follow this guide and do so before continuing.
Install and start Nginx
Once Homebrew is installed, run:
Then, once Nginx has been installed, start it by running:
To check that Nginx is correctly installed, and has started correctly, go to http://localhost:8080
. You should see the default Nginx page.
NOTE If you are installing Nginx on a remote Mac, you’ll need to substitute the localhost in the above URL for the IP address of the remote Mac. For example, if you have installed Nginx on a Mac at 10.0.1.10
, you’d type http://10.0.1.10:8080
.
Change the listening port
By default, Nginx listens on port 8080
on Macs. In most circumstances, you will want it to listen on port 80
instead. Before we do this, we need to temporarily stop Nginx from running:
Next, open the configuration file at /usr/local/etc/nginx/nginx.conf
:
The server
block in your /usr/local/etc/nginx/nginx.conf
file should look as follows:
Save your changes by pressing Ctrl + X
, then Y
, then Enter
. Then restart Nginx:
To test that the change worked, visit http://localhost
. You should see the default Nginx page.
NOTE As before, if you have installed Nginx on a remote Mac, you’ll need to substitute the localhost in the above URL for the IP address of the remote Mac. For example, if you have installed Nginx on a Mac at 10.0.1.10
, you’d type http://10.0.1.10
.
Set up sites-available and sites-enabled
Next, we need to set up the traditional sites-enabled
and sites-available
folder structure:
Having created this structure, we need to tell Nginx where to look for enabled sites. To do this, we’ll open /usr/local/etc/nginx/nginx.conf
again:
Then we need place the following line within the http
block:
Save your changes by pressing Ctrl + X
, then Y
, then Enter
.
Set macOS to run Nginx when it starts
Finally, we need to tell macOS to run Nginx when it starts. To do this, we’ll create a blank file named homebrew.mxcl.nginx.plist
in /Library/LaunchDaemons/
:
And paste the following into it (thanks to jimothyGator for the samples):
Save your changes by pressing Ctrl + X
, then Y
, then Enter
.
Set up your server blocks
Now you are ready to start creating server blocks in exactly the same way as you would in any other Nginx setup.
Versions
Notice an error?
Have we got something wrong? Please let us know and we’ll fix it right away.
Tags
Web ServerThere are following steps to install the Nginx on Mac OS:
Step 1: Download Homebrew
To install the Nginx on Mac OS, Homebrew must be installed on the system. Homebrew is a package manager for Mac operating system that allows us to install various Unix applications easily. If you don't have Homebrew, use the following link to install: https://brew.sh/
Or simply type the following command on the terminal:
Step 2: Update the Homebrew repository index
Update the repository index of the Homebrew package installer. This can be done through the brew update command.
Step 3: Install Nginx
The homebrew package installer will help to install the Nginx web server on the macOS. To install the Nginx, use the following command:
The Nginx server will install on the location /usr/local/cellar. The entire executable services related to starting and stopping Nginx are stored inside the bin folder of the installation directory.
The web server will listen by default on port number 8080. To start the Nginx, use the following command:
And to check whether the nginx is correctly installed on the computer, type the localhost on the browser or run the following command on the console:
To stop the Nginx services, use the following command:
Important locations:
- Add configs in -> /usr/local/etc/nginx/servers/
- Default config -> /usr/local/etc/nginx/nginx.conf
- Logs will be in -> /usr/local/var/log/nginx/
- Default webroot is -> /usr/local/var/www/
- Default listen address -> http://localhost:8080