Foreword: Recently, the company's rectification project, the front-end projects and interfaces are all re-deployed by Nginx, here is a summary of the knowledge points of the recently used Nginx server, and a Nginx Chinese document website is recommended.
The Nginx server will not be introduced, and we will go directly to the topic. The system uses the window7 flagship
First, download Nginx . Here I downloaded version 1.18. After decompression, I get the following Nginx root directory. It is recommended to put the root directory in the environment variable.
Then, enter cmd in the root directory navigation bar and press Enter to enter the command control
common commands:
nginx -t : Verify the configuration file
nginx -v: display the version
start nginx: start the server
nginx -s stop: quickly shut down the server
nginx -s quit: shut down the server normally
nginx -s reload: reload the configuration file
After that, we enter nginx start, and the system will flash a command console and then automatically close. At this time, open the task manager and find nginx.exe in the process, indicating that the startup is successful. Open 127.0.0.1 or localhost in the browser. The nginx welcome page will be displayed, indicating that the operation is successful.
Let’s introduce the basic configuration.
Open the conf folder in the root directory and open nginx.conf with an editor.
Agency service:
The following code can modify the path of the proxy website, access to the default port 80 will be directed to the index.html file under the html folder, which is the nginx welcome page, to achieve the proxy effect
server {
listen 80;#监听端口
server_name localhost;#监听域名访问
location / {
root html;#代理文件夹
index index.html index.htm;#代理文件
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Reverse proxy:
Use the above code to slightly modify to realize the reverse proxy function, enter http://127.0.0.1:1024/baidu to access Baidu
server {
listen 1024;#监听端口
server_name localhost;
location /baidu {
proxy_pass https://www.baidu.com/;#反向代理baidu网址
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
https service construction can refer to the previous establishment of an online version of the https construction in the remote video chat
The above is my compilation of the basic knowledge of nginx, I hope it will be helpful to you