Installing nginx on OS X Yosemite

Published on December 17, 2014 by

As always, there are many ways to accomplish this. My approach is based on Homebrew and assumes that you have it installed. If not, then the first thing you have to do is to install it.

Installing nginx on OS X

To install nginx, simply open up the Terminal and enter the following command.

brew install nginx

That’s it! Assuming that no errors occurred, then nginx is ready to start. But let’s first change the default port.

Changing nginx’ Default Port to 80

By default, nginx listens to port 8080, but let us change that to the default HTTP port, which is 80. To do that, we need to make a simple change to the configuration file /usr/local/etc/nginx/nginx.conf. You can do this with any text editor such as vi or nano.

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

Scroll a bit down and you should see the following.

server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

What you want to do is to simple change the number 8080 to 80 next to the listen keyword.

Testing

To start up nginx, simply enter the following command in the Terminal.

sudo nginx

nginx should now start up, and you can test that everything works by navigating to http://localhost in your browser.

If you have problems starting up nginx, a common problem is that the port that nginx is configured to listen to is already in use. If you changed the port to 80, then this could be an Apache web server or Skype, for instance.

Should you need to stop nginx, then you can do so with the below command.

sudo nginx -s stop

As you have seen, nginx is very simple to install and set up on OS X Yosemite (or any other version for that matter). Thank you for reading!

Author avatar
Bo Andersen

About the Author

I am a back-end web developer with a passion for open source technologies. I have been a PHP developer for many years, and also have experience with Java and Spring Framework. I currently work full time as a lead developer. Apart from that, I also spend time on making online courses, so be sure to check those out!

2 comments on »Installing nginx on OS X Yosemite«

  1. Jess

    Thanks so much for this guide! I’m a web designer installing nginx for the first time and you made it simple :D

Leave a Reply

Your e-mail address will not be published.