nginx负载均衡:
tar zxf nginx-1.15.9.tar.gz ##解压nginx包
cd nginx-1.15.9
vim src/core/nginx.h ##去掉nginx的版本号
vim auto/cc/gcc ##注释安装的debug模式,降低安装的nginx的大小
./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module ##选择编译路径,添加模式
yum install gcc -y ##安装缺少编译软件gcc,源码编译缺少什么依赖性,就安装什么依赖性
./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module
yum install pcre-devel -y
./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module
yum install openssl-devel -y
./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module ##编译成功
make && make install ##安装
cd /usr/local/
vim nginx.conf ##编辑配置nginx文件
useradd nginx ##启动nginx时,需要使用nginx用户,但没有此用户,需要添加
ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/ ##做出软链接,使nginx可以直接通过命令nginx启动
nginx
netstat -antlp ##查看nginx端口是否打开
cd ../html/ ##编辑初始化显示页面(nginx此时就被当作web服务器)
vim index.html
cd /usr/local/lnmp/nginx/
du -sh nginx/ ##查看编译安装的nginx的大小
cd /usr/local/lnmp/nginx/ ##分离初始化界面,实现虚拟主机
mkdir www
mkdir bbs
mkdir blog
cd bbs/
echo bbs.westos.org>index.html
cd ../blog/
echo blog.westos.org>index.html
cd ../www/
echo www.westos.org>index.html
vim /mnt/lnmp/nginx-1.15.9/src/core/nginx.h
14 #define NGINX_VER "nginx/" ##去除编译配置软件的版本号
vim /mnt/lnmp/nginx-1.15.9/auto/cc/gcc
171 # debug
172 #CFLAGS="$CFLAGS -g" ##去除debug模式,不安装
vim /usr/local/lnmp/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
upstream westos { ##做出轮询策略
server 172.25.30.2:80;
server 172.25.30.3:80;
}
server { ##定义服务监控端口,域名,以及初始化界面
listen 80;
server_name bbs.westos.org;
location / {
root html/bbs;
index index.html;
}
}
server {
listen 80;
server_name blog.westos.org;
location / {
root html/blog;
index index.html;
}
}
server { ##定义服务端口,域名,定义使用轮询策略
listen 80;
server_name www.westos.org;
location / {
proxy_pass http://westos;
}
}
}