preface

Nginx is used to deploy front-end static resources and reverse proxy background interfaces on Linux servers.

nginx

Introduction to the

website

Engine X (NGINx) is a lightweight Web/reverse proxy server and email proxy server.

Install the configuration

The installation

After the installation, run nginx -v to check whether the installation is successful.

Command line arguments

  • Nginx -v can be used to query the version
  • Nginx -t tests configuration files
  • nginx -s signal
    • Nginx -s stop Stops quickly
    • Nginx -s quit gracefully closes (after processing all requests)
    • Nginx -s reopen the log file
    • Nginx -s reload reload configuration (start a new worker process to use the new configuration, gracefully close the old worker process)
  • Nginx -p prefix name Set nginx path prefix (default /usr/share/nginx)
  • Nginx -c file name sets the new configuration file
  • Nginx -g directive name sets the global directive

The configuration file

After Linux is installed, there is a default nginx.conf configuration file in the /etc/nginx directory.

Nginx configuration files are mainly composed of several command-controlled modules. These instructions include simple instructions and block-level instructions (modules). Simple instructions include names and arguments, with Spaces between them and ending with commas. The module consists of curly braces. Use # to comment.

All the instructions listed on the website

Server,

Official website Server explanation

The LISTEN command listens to the IP addresses and port numbers that connect to the virtual server. The server_name command lists all server names.

listen

Listen

  • Listen 127.0.0.1:8000;
  • Listen 127.0.0.1;
  • listen 8000;
  • listen *:8000;
  • listen localhost:8000;

For IP addresses only, the default is port 80.

server_name

Break down

location

The location value can be a specific string or a regular expression. Nginx checks for specific strings first and takes a location that matches the longest string defined. Check the order in which the regular expression appears in the configuration file. If no regular expression is matched, the previous location is used.

  • The ~* modifier ignores case
  • The ~ modifier is case-sensitive
  • The ^~ modifier does not use a re
  • = modifiers match exactly
  • @ redirect

proxy_pass

Website to explain

Sets the protocol and address of the proxied virtual server based on the URI matched in a particular location. The HTTP or HTTPS protocol must be used. The address can be a domain name or IP address (the port number is optional). Such as:

proxy_pass http://localhost:8000/uri/;
Copy the code

Nginx variable

All the variables listed on the website

For example, $host $remote_addr

A simple demo

/data/vue-app/dist
/
try_files
/api/
/api/login

eggjs