一、Ubuntu 编译安装 nginx
1.1 安装依赖
sudo apt install libgd-dev
1.2、下载nginx
wget http://nginx.org/download/nginx-1.22.1.tar.gz
1.3、解压nginx
tar -zvxf nginx-1.22.1.tar.gz
1.4编译安装
cd nginx-1.22.1
1.5、编译并制定安装位置
./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
make && make install
1.6、测试(用浏览器输入ubuntu地址(本机:192.168.0.168)
二、网络搭建
在/usr/share/nginx/html 创建网页
设置负载均衡(这里只实现反向代理,负载均衡如下原理即可)
upstream nginx_boot(这个名字可自行更改){
# 30s内检查心跳发送两次包,未回复就代表该机器宕机,请求分发权重比为1:2
server 192.168.0.000:8080 weight=100 max_fails=2 fail_timeout=30s;
server 192.168.0.000:8090 weight=200 max_fails=2 fail_timeout=30s;
weight是设置权重决定命中率到达负载均衡的效果
除了权重算法以为还可以通过反向代理算法设置策略
# 这里的IP请配置成你WEB服务所在的机器IP
}
server {
location / {
root html;
# 配置一下index的地址,最后加上index.ftl。
index index.html index.htm index.jsp index.ftl;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 请求交给名为nginx_boot的upstream上
proxy_pass http://nginx_boot;
}
}
至此,即可进行访问