Installing nginx on macOS Mojave using brew

Carvia Tech | May 05, 2019 | 2 min read | 74 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

Top articles in this category:
  1. Install and upgrade Jenkins on Ubuntu
  2. Install Artifactory OSS private maven repository
  3. Basic Unix commands for every programmer



Find more on this topic:
Dev Ops image
Dev Ops

Dev Ops Automation - Ubuntu OS, Centos, MySql, MongoDB, Java, AWS Infrastructure.

Last updated 1 month ago


Recommended books for interview preparation:

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