This is my first article on getting started

People's life and different people or different things have indissoluble bond, and our front-end development has indissoluble bond is Nginx. This article won't tell you how to use it in detail, but will let you complete the configuration of the Nginx environment and the deployment of the project code, which I think is enough for most people.Copy the code

Learn about Nginx

What exactly is Nginx?

  • Nginx (Engine X) is a high-performance HTTP and reverse proxy Web server that also provides IMAP/POP3/SMTP services.
  • Nginx is a lightweight Web/reverse proxy server and E-mail (IMAP/POP3) proxy server distributed under the BSD-like protocol.

Nginx features:

  • Less memory
  • Strong concurrency

Nginx is simply a server on which our front-end needs to deploy code. On this server we can do two things: 1. When obtaining data, you can configure the proxy for the requested address; 2. Put the code on this server so that others can access our project through the address. Of course, there is a prerequisite for this: the network environment should be accessible to others.

Nginx environment configuration

On Windows, you can unzip the folder and start it by double-clicking nginx.exe. This process is easy to learn and will not be described in detail. Here is the configuration of the Linux system:

Install dependencies

As the saying goes, to do a good job, you must sharpen your tools. We need to download the required dependencies before configuring the environment.

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel
Copy the code

Download the zip package (a version of nginx.tar.gz), nginx download address

You are advised to download a Stable version. This section uses nginx-1.18.0 as an exampleCopy the code

Installation steps

  1. The installation directory is displayed
cd /usr/local
Copy the code
  1. Upload the file and select the downloaded package
rz
Copy the code
  1. Decompression package
The tar - ZXVF nginx - 1.18.0. Tar. GzCopy the code
  1. The decompressed folder is displayed
cdNginx - 1.18.0Copy the code
  1. Specify the installation location of the next compiled file
./configure --prefix=/usr/local/ nginx - 1.18.0Copy the code
  1. compile
make
make install
Copy the code

If the sbin folder is successfully compiled, check whether an error occurs.

Start the service

Go to the sbin folder and start the service

cd sbin	
./nginx
Copy the code

After the preceding command is executed, the following error is reported, indicating that the log file is missing.

nginx:  open() "/ usr/local/nginx - 1.18.0 / logs/error log" failed (2: No such file or directory)
open() "/ usr/local/nginx - 1.18.0 / logs/access log" failed (2: No such file or directory)
Copy the code

The solution is as follows (with the above error, we need to go back to the nginx-1.18.0 folder) :

Log create the error. Log file touch access.log create the accessCopy the code

Enter the sbin folder again and type./nginx.

Proxy configuration

  1. The configuration steps
cd /usr/localConf Edit the nginx.conf file. Press A to start editing the file. Press ESC to exit the editing modeCopy the code
  1. Configuration content (Some of the configuration in Sever, but enough for most people)
Server {# port number change listen8088; Localhost server_name xxx.yyy.com; location / { root html; index index.html index.htm; } # configure proxy # /varExample :axios.get(/var/API path)varIs a variable that can be named any way # HTTP:// IP :port Proxy address
        location /var {
            rewrite  ^.+var/? $/ $(. *)1 break;
            include  uwsgi_params;
            proxy_pass   http://ip:port;}}Copy the code
  1. Verify that the configuration is correct
cd /usr/local/ nginx - 1.18.0 / sbin/nginx - tCopy the code

If the following information is displayed, the configuration is successful. Otherwise, you need to check the cause of the error

nginx.conf syntax is ok
nginx.conf test is successful
Copy the code

Code deployment

  1. Start by finding the deployment directory
cd /usr/local/nginx-1.18.0/ HTML or use the file transfer tool directly enterCopy the code
  1. The deployment code
Rz Upload the project package xxx.zip unzip xxx.zipCopy the code

conclusion

  1. If no command is available, download the corresponding command
  2. Common Nginx commands
/nginx -s quit exit./nginx -s reload Restarts the loadingCopy the code
  1. I hope I can give you a reference to the problems I actually encountered
  • Ping IP Indicates whether the device can be pinged through
  • Firewall port number Specifies whether to allow access. By default, 80 has firewall Settings
  • The most basic point: IP address is not configured to access virtual machines, such as Ali Cloud, Huawei cloud and so on. !!!!!!!!! I checked for a long time for this reason, all other configurations were passable, then external machines were not accessible, and I was later informed that IP was not configured.