Installing nginx on macOS Mojave using brew

Munish Chandel | April 15, 2019 at 09:24 AM | 29 views


Installing nginx with homebrew is very easy on macOS X/Mojave. In this article we will cover nginx installation, configuration and start/stop.

Install nginx

Use brew to install nginx with below command:
$ brew install nginx

This command will install nginx and set default port in /usr/local/etc/nginx/nginx.conf to 8080 (so that you can run nginx without sudo), so you can access nginx at http://localhost:8080

There are two ways you can start nginx on your mac:

using brew services

this option will launch nginx now and restart at login in background mode:

Start nginx
$ brew services start nginx
Stop nginx
$ brew services stop nginx
without service

If you don’t want to start nginx in background mode, then you can can just run the below command to start nginx

Start nginx
$ sudo nginx
Stop nginx
$ sudo nginx -s stop

Configure nginx

The default place of nginx.conf on macOS after installing with brew is:

$ vi /usr/local/etc/nginx/nginx.conf

You can change the default port of server to something else, for example 9090, as shown below:

/usr/local/etc/nginx/nginx.conf
server {
        listen       9090;
        server_name  localhost;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

now restart the server for changes to take effect:

Restart server
$ sudo nginx -s stop
$ sudo nginx

Now browse the new url:

http://localhost:9090

Upgrade brew

If you just want to upgrade the existing installation using brew, you can simply run the below command:

Update brew
$ brew upgrade

We can cleanup older installation artifacts using cleanup command.

Cleanup brew
$ brew cleanup

Uninstall nginx

Below brew command can be used to uninstall nginx completely.

$ brew uninstall nginx


You may also be interested in..
Generic placeholder image
ebook PDF - Cracking Spring Microservices Interviews for Java Developers
You may also be interested in..
Generic placeholder image
ebook PDF - Cracking Java Interviews v3.4 by Munish Chandel

Similar Articles:
  1. Basic Unix commands for every programmer
  2. Install Artifactory OSS private maven repository
  3. Installing nginx on macOS Mojave using brew
You may also be interested in..
Generic placeholder image
ebook PDF - Cracking Spring Microservices Interviews for Java Developers
You may also be interested in..
Generic placeholder image
ebook PDF - Cracking Java Interviews v3.4 by Munish Chandel
Facebook Page
Related Topics
Free Email Updates

Enter your email address to subscribe to this blog and receive notifications of new posts by email.


This website uses cookies to ensure you get the best experience on our website. more info