$ brew install nginx
Installing nginx on macOS Mojave using brew
Upasana | July 10, 2019 | 2 min read | 5,623 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 on macOS
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:
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:
$ sudo nginx -s stop $ sudo nginx
Now browse the new url:
http://localhost:9090
Upgrade brew
If you just want to upgrade the existing nginx installation using brew, you can simply run the below command:
$ brew update $ brew upgrade nginx
The above two commands will update the application metadata and then upgrade only nginx installation.
Or you can even upgrade all the existing applications using brew:
$ brew upgrade
This command will update all the existing applications installed through brew. |
We can cleanup older installation artifacts using cleanup command.
$ brew cleanup
Uninstall nginx
Below brew command can be used to uninstall nginx completely.
$ brew uninstall nginx
Top articles in this category:
- Install & configure Redis on Ubuntu
- Install ElasticSearch 7 on Ubuntu 20.04
- Install Cassandra 4 on Ubuntu 20.04
- Install RabbitMQ and Erlang 23 on Ubuntu 20
- Install OpenJDK 11 on Ubuntu 18.04 LTS
- MySql 8 installation on Ubuntu 20
- Upgrade Jenkins on Ubuntu 18.04 LTS