There are following steps to install the Nginx on Mac OS:
Create the SSL Certificate. Create the requisite directories: mkdir -p /usr/local/etc/ssl/private. This page shows how to install Nginx on Mac OS using 'brew' $ brew install nginx Incase if your system didnot recongize this command, then install homebrew first by running below command and rerun above command once again. Go back to the operating system / installation method selection menu. Table of contents. Step 1: install Passenger package. Step 2: enable the Passenger Nginx module and restart Nginx. This is not wise to do on a production server. On a new Mac dev setup, this is perfectly fine. Sudo killall php-fpm Nginx. Brew install nginx sudo nginx. Now, test the install is working. Now, change the default settings. Code /usr/local/etc/nginx/nginx.conf.
How to Install Nginx on MacOS Introduction. Nginx is a web server which can also be used as a HTTP cache, load balancer and reverse proxy.This was first created by Igor Sysoev and released in 2004 under the terms of BSD like license. In this tutorial, we will learn the steps involved in the installation of Nginx.
Step 1: Download Homebrew
To install the Nginx on Mac OS, Homebrew must be installed on the system. Homebrew is a package manager for Mac operating system that allows us to install various Unix applications easily. If you don't have Homebrew, use the following link to install: https://brew.sh/
Or simply type the following command on the terminal:
Step 2: Update the Homebrew repository index
Update the repository index of the Homebrew package installer. This can be done through the brew update command.
Step 3: Install Nginx
The homebrew package installer will help to install the Nginx web server on the macOS. To install the Nginx, use the following command:
The Nginx server will install on the location /usr/local/cellar. The entire executable services related to starting and stopping Nginx are stored inside the bin folder of the installation directory.
The web server will listen by default on port number 8080. To start the Nginx, use the following command:
Install Nginx On Mac Os
And to check whether the nginx is correctly installed on the computer, type the localhost on the browser or run the following command on the console:
To stop the Nginx services, use the following command:
Important locations:
- Add configs in -> /usr/local/etc/nginx/servers/
- Default config -> /usr/local/etc/nginx/nginx.conf
- Logs will be in -> /usr/local/var/log/nginx/
- Default webroot is -> /usr/local/var/www/
- Default listen address -> http://localhost:8080
How do you get nginx to load and run when your Mac boots up, while still having it run on port 80?
it’s a problem I’ve been trying to solve for near a year now. And it seemed that no amount of blog post reading or trial and error would work… but I finally found the answer today!
Start nginx With launchctl, When Your Mac Boots Up
The root of the fix is one thing that I wasn’t aware of previously. You need to put your plist file in /Library/LaunchDaemons, not in ~/Library/LaunchAgents like the Homebrew instructions say to do. You also need to copy the file over, not just symlink it – again, going against the Homebrew instructions. Lastly, use the -w option with launchctl.
And now nginx will load when you reboot your system!
Why Does This Work?
The trick to this is that Mac OSX won’t let anything other than “root” or “system” level services use a port number below 1024. This is well documented and well known, but the solution to the problems seems to have been left to the “you should know this, and I’m not going to tell you if you don’t already know it” realm of open source community douche-baggery. But when you want and/or need nginx to load on port 80 (like I do), then you have to jump through some magic hoops that the homebrew installation doesn’t tell you.
LaunchDaemons
Mac Nginx Php
The first trick is that you don’t want to run nginx as your user. If you do that, you have to run it as a sudo command, which typically involves a lot of dumb workarounds and script files. No thanks.
Instead of trying to use ~/Library/LaunchAgents, then, you need to use the system launch daemons folder. This will let the plist file run the command as a system level service, giving it access to port 80.
Copy The File. Don’t Symlink It
The second trick is that you need to copy the plist file in to the /Library/LaunchDaemons folder, instead of just symlinking it. I tried a symlink first, but it fails saying there are permissions errors with the path. Even if you sudo symlink it, it will fail due to permissions problems on the original file, not the symlink itself.
So instead of creating a symlink like the Homebrew instructions say, just copy the .plist file to the LaunchDaemons folder. The potential damage here, is if the default plist file for nginx changes. But you can always just replace the LaunchDaemons file when you update nginx.
Use -w With Launchctl
The last trick is the -w option when loading and unloading nginx. This might not strictly be necessary, but I read a few places that said it was needed. From what I understand, using -w will toggle the “disabled” flag when you unload / load the service. I guess that will stop the service from loading on startup when you unload it, and allow it to run when you load it with this flag.
Hope That Helps
You should know that this doesn’t start nginx when you log in. Rather, it starts it when OSX boots up. This is necessary, though, if you want to use port 80 without stupid hacks.
Mac Nginx Stop
I certainly didn’t figure this out myself. It took me a ton of work and trying and digging to get it working. The largest help that I found was on Steven Octo’s blog (link no longer working, so I removed it). He got me turned in the right direction with copying the plist file and using LaunchDaemons. Thanks, Steven!