1. Is brew installed on the computer?
1.1 Terminal input command: which brew
If the following picture is displayed, it proves that it has been installed.
If it is not installed, the terminal executes the following instructions:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
To check whether the installation is successful, execute the command:brew -v
2 At this point, brew is already available, start installing Nginx
Execution instructions:
brew install nginx
Check whether the installation has been completed and execute the command:nginx -v
as shown in the figure below, which means the installation has been successful;
3 At this point, Nginx has been installed and started.
A brief introduction to several commonly used instructions:
- Startup command:
nginx
orsudo nginx
- Restart Nginx instructions:
sudo nginx -s reload
- Stop Nginx command:
sudo nginx -s quit
, or directly:killall nginx
.
Check whether it has started successfully: ps -ef | grep nginx
as shown below, it means it has started successfully:
or directly enter localhost:8080 as the URL, if the following picture appears, it means it has been successful:
4. The 8080 port of some computers has been occupied. The startup may not be successful. You can change the port number.
To change the port number, you need to find the file nginx.conf. The operation is as follows:
Execute the command to find the directory where the configuration file is located: nginx -t
The following figure is the directory where nginx.conf is located:
Execute the command: open /opt/homebrew/etc/nginx/
, enter this directory, and then right-click the mouse and use the built-in Just open it with a text editor:
The picture below shows the setting of the port number. I have changed it to 8082 here;
5 At this point, Nginx has started normally. Next, we start the actual deployment.
5.1 Step 1: Find the directory where Nginx is located,Note that this is not the directory of nginx.conf, but the installation directory of Nginx., execute the command: brew info nginx
, as shown in the figure below:
Note that there are two directories here. These two directories must be distinguished. We are using the installation directory of nginx;
Open this directory: open /opt/homebrew/Cellar/
5.2 Step 2: Copy your front-end file to the html file in this directory, as shown below: At
this time I have put my front-end file in;
5.3 Step 3: Modify the nginx.conf file again, The purpose is to find your front-end file. The way to open nginx.conf is as mentioned above, which is to open the file that changes the port number:
Specify the location of the front-end project: My front-end file is soulsys under the html folder. Open the login.html I set on the page. Note that I changed the port number here to 8086:
6 projects started running
Start the backend, and then start nginx. You need to pay attention here. You can also start nginx of your project in the bin directory, as shown in the following figure:
Or directly enter the terminal command nginx
to start. Remember that if nginx has been started, remember to restart nginx after deployment and restart the command.sudo nginx -s reload
.As
shown below, it means that it has been started successfully:
7 tests
Started successfully!!!