Linux enterprise actual combat-----Realize reverse proxy load balancing through nginx + nginx virtual host

Realize reverse proxy load balancing through nginx

    cd /root/nginx-1.19.1/auto/cc
    vim gcc

Insert picture description here

    cd /root/nginx-1.19.1/src/core/
    vim nginx.h     隐藏版本

Insert picture description here

    cd /usr/local/nginx/sbin
    ./nginx
    cd /usr/local/nginx/logs
    ls                            启动nginx后查找其pid文件位置

Insert picture description here

	ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin  添加软连接
    cd /lib/systemd/system
    vim nginx.service         编辑nginx启动脚本
    systemctl daemon-reload

Insert picture description here

    vim /etc/security/limits.conf 
     
    useradd -M -d /usr/local/nginx/ -s /sbin/nologin nginx   创建用户nginx,后面配置文件会用到

Insert picture description here

    vim /usr/local/nginx/conf/nginx.conf
     
    systemctl reload nginx

Insert picture description here
Insert picture description here
Insert picture description here

Use curl to access server2 in server1 and find that load balancing has been achieved

Insert picture description here

You can also set the access weight algorithm

Set the weight of server3 to 3:
Insert picture description here
Insert picture description here

The health check that nginx comes with:

server4:
 
systemctl stop httpd

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_42958401/article/details/109310570