Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”

This article also participated in the “Digitalstar Project” to win a creative gift package and creative incentive money

Portal: Nginx installed on Linux

1. Install and use Nginx

Download the Nginx installation package

Official website download addressSelect the Windows version to download and unzip

Start the Nginx

  • Method 1: Double-click nginx.exe directly, double-click a black pop-up window flash past;
  • Open CMD command window, switch to nginx decompression directory, enter the command
  start nginx
Copy the code

Check whether Nginx is started successfully

  • Method 1: In the address box of the browser, enter http://localhost:80 and press Enter. If the following page is displayed, the server is successfully started.

  • Method 2: In the CMD window, run the tasklist /fi “imagename eq nginx.exe” command. If the following information is displayed, the vm is successfully started.

The configuration file for nginx is nginx.conf in the conf directory. By default, nginx is configured to listen on port 80. If port 80 is occupied, change it to an unused port.

You can run the following command to check whether port 80 is occupied:

netstat -ano | findstr 0.0.0.0:80 
# or
netstat -ano | findstr "80"
Copy the code

Restart the Nginx

When modifying the nginx configuration file nginx.conf, you do not need to shut down nginx and then restart nginx. Simply open CMD (Powershell needs to be run as an administrator), switch to the nginx directory and run the following command.

nginx -s reload 
Copy the code

Close the Nginx

If you use the CMD command window to start nginx, closing the CMD window will not end the nginx process. Nginx can be turned off in two ways:

  • Nginx -s quit nginx -s quit nginx -s quit
nginx -s stop
Copy the code
nginx -s quit
Copy the code
  • Method 2: Use taskkill
taskkill /f /t /im nginx.exe
Copy the code

2. Deploy the Vue project to Nginx

  • Copy the packaged dist file of the project into the HTML folder

  • Modify the nginx.conf file

Change server, root default HTML to: HTML /dist. Nginx will find index.html in dist and open it

After modification, nginx -s reload restarts

Enter localhost:8090 in the browser to check whether it is successful. Mobile phone access needs to be in the same LAN as computer;