The use of mac version Nginx and the actual deployment of web projects-the simplest way

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.
Insert image description here
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
Insert image description here

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;
Insert image description here

3 At this point, Nginx has been installed and started.

A brief introduction to several commonly used instructions:

  • Startup command: nginxorsudo 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:
Insert image description here
or directly enter localhost:8080 as the URL, if the following picture appears, it means it has been successful:
Insert image description here

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:
Insert image description here
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:
Insert image description here
The picture below shows the setting of the port number. I have changed it to 8082 here;
Insert image description 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:
Insert image description here
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/
Insert image description here
5.2 Step 2: Copy your front-end file to the html file in this directory, as shown below: At
Insert image description here
Insert image description here
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:

Insert image description here

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:
Insert image description here
Insert image description here
Or directly enter the terminal command nginxto 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:
Insert image description here

7 tests

Insert image description here
Started successfully!!!

Guess you like

Origin blog.csdn.net/Onion_521257/article/details/127328496