Nginx服务

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;
}
}
}

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值