负载均衡实验

安装依赖

sudo apt install libgd-dev

下载nginx
wget http://nginx.org/download/nginx-1.22.1.tar.gz
 

解压nginx
tar -zvxf nginx-1.22.1.tar.gz
 

编译安装
cd nginx-1.22.1
 

编译并指定安装位置,执行安装之后会创建指定文件夹/www/env/nginx
./configure --prefix=/www/env/nginx \
--with-pcre \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_image_filter_module \
--with-http_slice_module \
--with-mail \
--with-threads \
--with-file-aio \
--with-stream \
--with-mail_ssl_module \
--with-stream_ssl_module 

结果:

nginx常用命令

nnginx-s reload修改配置后重新加载生效

快速停止nginx

nginx-s stop

nginx-s start

启动nginx

nginx-s quit完

整有序的停止nginx

查看nginx的版本nginx-v

nginx-V

查看版本和nginx的配置选项

nginx-t-c/path/to/nginyx.con以测试nginx

配置文件是否正确重新打开日志文件

nginx-s reopen、

启动nginx: ps -ef | grep nginx

public class IndexNginxController {
    @Value("${server.port}")
    private String port;
​
    @RequestMapping("/")
    public ModelAndView index(){
        ModelAndView model = new ModelAndView();
        model.addObject("port", port);
        model.setViewName("index");
        return model;
    }
}

在该Controller类中,存在一个成员变量:port,它的值即是从application.properties配置文件中获取server.port值。当出现访问/资源的请求时,跳转前端index页面,并将该值携带返回。

<html>
    <head>
        <title>Nginx演示页面</title>
        <link href="nginx_style.css" rel="stylesheet" type="text/css"/>
    </head>
    <body>
        <div style="border: 2px solid red;margin: auto;width: 800px;text-align: center">
            <div  id="nginx_title">
                <h1>$hello world 192.16.10.10{port}号!</h1>
            </div>
        </div>
    </body>
</html>

工作准备就绪后,再修改一下nginx.conf的配置即可.

所有的前提工作准备就绪,紧接着再启动Nginx,然后再启动两个web服务,第一个WEB服务启动时,在application.properties配置文件中,将端口号改为配置中的第一个端口号,第二个WEB服务启动时,将其端口号改为第二个端口号

  • 34
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值