Install Nginx and configuration in Linux

A brief introduction to Nginx

What is Nginx?

  • 1)--Nginx is a high-performance HTTP and reverse proxy web server.

  • 2) - In fact, the concurrency of Nginx performs better in the same type of web server.

  • 3)-The users of Nginx websites in Mainland China include: Baidu, JD, Sina, Netease, Tencent, Taobao.

  • 4)--Nginx can be compiled and run on most Unix Linux OS.

  • 5)-In the case of high concurrency, Nginx is a good alternative to Apache services: Nginx in the United States is one of the software platforms that bosses who do virtual hosting business often choose.

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

image.png


Nginx installation steps

Enter the official website to download the Linux version of Nginx

http://nginx.org/en/download.html

image.png
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

image.png

  • MoboXtem also switches directories
    image.png
  • Drag the compressed package in
    image.png
  • ls command to check whether the import is successful, if the picture is the same, it means that it is successful
    image.png

Unzip the compressed package of Nginx

Unzip command

    tar -xvf (Nginx的压缩包)

image.png
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

image.png
The name of the file has been changed


Install nginx server

说明:在nginx-source的根目录中执行如下命令

./  命令是执行的意思(执行程序)
1) - Execute the ./configure command

image.png

result

image.png
Mainly look at the above two lines, which is the working directory of Nginx

2) - Execute make in the root directory of nginx-source

image.png

image.png

3) - execute make install in the directory

image.png

Nginx working directory description

Description: Find working directory
路径: whereis nginx
image.png

Jump to the Nginx working directory

image.png

nginx command

1.启动命令: ./nginx
2.重启命令: ./nginx -s reload
3.关闭命令: ./nginx -s stop

进入nginx/sbin目录中执行

nginx working directory
image.png
path to execute the command
image.png


Modify Nginx configuration file

Enter the configuration file and open the picture is the directory of the configuration file and the configuration file
image.png

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

image.png

  • Import the Nginx configuration path in MobaXtem and open the configuration file
    image.png

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. . . . . .

Guess you like

Origin blog.csdn.net/weixin_45103228/article/details/113756920