top of page
  • Writer's pictureArjav Dave

Simple Configuration of NGINX on MAC: Part (2)

Updated: Jul 23, 2022

Configuration file

Your Nginx configuration file will be located at /usr/local/etc/nginx/nginx.conf

You can fire

nginx -t

to run a test configuration just to verify the location. Open the nginx.conf file to see it’s contents. I usually use Microsoft’s VS Code to edit any text files, so I ran the below command to open the file in VS Code. You can use any text editor you want.

code /usr/local/etc/nginx.conf

Once open you will see a the config file already has content in it most of which is commented out. You can clear everything so that we can take one step at a time. Run nginx -t to test the configuration file we just cleared out. It will give an error saying no "events" section in configuration which simply means there is no events context. Add the events context as follows:

events {

The events context helps you with configuration of the server like how many worker connections can be open at the same time and how polling happens among them.

Now when you run nginx -t you will not get any error but when you open you will be faced with This site can’t be reached error since we have not set our server locations yet. Time to do that!

Below your events context add another context with name http. Inside http context add context with name server. Finally, inside server context add context named location. It should look like below.

events { } http { server { # We are configuring for the / location location / { } } }

We have created a skeleton inside which we will now put some flesh and bones. Add a root directive inside the location context with a path pointing to your html directory. For demo purposes I have created a www folder on my Desktop. You can place your folder where ever you like. In the folder I have created an index.html with content <h1>HELLO WORLD</h1>. Here is the overall config file

events {} http { server { # listen on the port 8080 listen 8080; # When is visited, serve content from www on Desktop location / { root /Users/arjav/Desktop/www; } } }

That’s it!!! This is the simplest configuration you can have in nginx. From your terminal run nginx -s reload to reload nginx and visit in your browser and you will see a nice big HELLO WORLD. Press Cmd+Shift+R to hard refresh your browser in case you are seeing some cached content.

2,851 views2 comments

Recent Posts

See All


Akshit Gaur
Akshit Gaur
Jul 05, 2023

There is no etc dir in /usr/local

Arjav Dave
Arjav Dave
Jul 05, 2023
Replying to

Hello, You can run "nginx -t" to get the location of your configuration file.

bottom of page