Article directory
Reference article address
Homebrew install nginx
After ensuringMacOS installation of Homebrew is successful, execute the following command
brew install nginx
Note: After Nginx is installed successfully, the directory location will be prompted; each person’s system may be different due to the different installation locations of Homebrew, so these directory locations should be noted down for convenience. Later configuration and maintenance of Nginx
According to the picture above, we can see the locations of several important files on my machine:
nginx.conf
Placement statement:/opt/homebrew/etc/nginx/nginx.conf
- Loading location of static resources:
/opt/homebrew/var/www
- nginx startup command:
brew services start nginx
or/opt/homebrew/opt/nginx/bin/nginx -g daemon off
In fact, they are all in my local Homebrew installation directory /opt/homebrew
brew starts Nginx
1. Normal startup
brew services start nginx
2. Non-background operation
If you want to run nginx in "non-background" mode, you can use the following command:
This command executes the nginx script file in the form of an absolute path; so it may not be suitable for you (you may not be able to find this file), because it is closely related to the Homebrew installation path of your own system, here / opt/homeberw is my own Homebrew installation path.
If the file cannot be found, you can try/usr/local/opt/nginx/bin/nginx -g daemon off
. If you are interested in the specific reasons, you cansee this blog
/opt/homebrew/opt/nginx/bin/nginx -g daemon off;
3. Restart Nginx
brew services restart nginx
brew close Nginx
brew services stop nginx