A brief introduction to Nginx
What is Nginx?
What is a reverse proxy?
1)-The reverse proxy server is located between the user and the target server, but for the user, the reverse proxy server is equivalent to the target server.
2)-The user does not need to know the address of the target server, nor does it need to make any settings on the user side. Reverse proxy servers are usually used as web acceleration.
3)-Use reverse proxy as the front end of the web server to reduce the load of the network and server and improve access efficiency.
advantage:
Improved internal server security
Speed up access to internal servers
Saved limited IP resources
Nginx installation steps
Enter the official website to download the Linux version of Nginx
http://nginx.org/en/download.html
After downloading, we upload the installation package to Linux.
Tip: I am using MobaXterm remote link software
Upload Nginx compressed package
The designated directory we upload to:/usr/local/src
- MoboXtem also switches directories
- Drag the compressed package in
- ls command to check whether the import is successful, if the picture is the same, it means that it is successful
Unzip the compressed package of Nginx
Unzip command
tar -xvf (Nginx的压缩包)
After executing the command, the directory of the picture appears, indicating that it is successful
推荐:可以删除Nginx的压缩包
Modify the name of the Nginx file
mv nginx-1.19.6 nginx-source
The name of the file has been changed
Install nginx server
说明:在nginx-source的根目录中执行如下命令
./ 命令是执行的意思(执行程序)
1) - Execute the ./configure command
result
Mainly look at the above two lines, which is the working directory of Nginx
2) - Execute make in the root directory of nginx-source
3) - execute make install in the directory
Nginx working directory description
Description: Find working directory
路径: whereis nginx
Jump to the Nginx working directory
nginx command
1.启动命令: ./nginx
2.重启命令: ./nginx -s reload
3.关闭命令: ./nginx -s stop
进入nginx/sbin目录中执行
nginx working directory
path to execute the command
Modify Nginx configuration file
Enter the configuration file and open the picture is the directory of the configuration file and the configuration file
demand
Our purpose of changing the configuration file is to realize the reverse proxy when the project goes online in the future, which is the reverse proxy
of the picture, and the load balancing of tomcat, so we implement the following functions in the configuration file
Implementation
- Import the Nginx configuration path in MobaXtem and open the configuration file
Configuration
打开配置文件后http里面开始写
Realize the reverse proxy of pictures
server{
listen 80;
server_name image.jt.com
location / {
root /user/local/src/images;
}
}
Configure reverse proxy in server
listen is the port number
server_name is the domain name of the reverse proxy
location / configure the path inside
root is the path to the picture
Realize the reverse proxy of the domain name
如果我们有域名的话,那就可以写域名,
Configure the background server
server{
listen 80;
server_name manage.jt.com;
location / {
proxy_pass http://jtWindow;
}
}
upstream jtWindow{
server localhost:8081;
server localhost:8082;
server localhost:8083;
}
这些配置是反向代理的核心,
proxy_pass refers to the cluster address of the tomcat server
Write tomcat cluster and configuration in upstream (define cluster)
server is the location where the tomcat service is written, that is to say the domain name
现在的情况是 设定三个tomcat服务器的反向代理
All the following configuration and installation have been realized
If there is no domain name, temporarily return the linux local ip address to the domain name
For example: Change 192.168.126.131 to manage.jt.com
The specific implementation will not be mentioned for the time being. . . . . .