网站首页 > 技术教程 正文
Nginx调度后端的不同虚拟主机项目(老男孩)
如果对运维课程感兴趣,可以在b站上搜索我的账号: 运维实战课程,可以关注我,学习更多免费的运维实战技术视频
项目 源码安装nginx服务并配置调度器,后端的两个web,都有虚拟主机:baidu和souhu,域名都是:
www.baidu.com 和 www.souhu.com 只是网页内容有点不同以作为区别。当访问百度时候,会轮询调度到后端的两个百度上,当访问搜狐的时候,也会轮询访问后面的两个搜狐上,需要做设置,否则当访问搜狐的时候,可能会访问到百度页面。
在192.168.4.5(nginx调度器) //安装nginx并配置调度器
[root@localhost 桌面]# yum -y install gcc gcc-c++
[root@localhost 桌面]# yum -y install openssl-devel openssl zlib zlib-devel pcre pcre-devel
[root@localhost 桌面]# ls
nginx-1.6.2.tar.gz
[root@localhost 桌面]# tar -zxf nginx-1.6.2.tar.gz
[root@localhost 桌面]# ls
nginx-1.6.2 nginx-1.6.2.tar.gz
[root@localhost 桌面]# cd nginx-1.6.2
[root@localhost nginx-1.6.2]# ls
auto CHANGES.ru configure html man src
CHANGES conf contrib LICENSE README
[root@localhost nginx-1.6.2]# useradd -s /sbin/nologin -M nginx
[root@localhost nginx-1.6.2]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
[root@localhost nginx-1.6.2]# make && make install
[root@localhost nginx-1.6.2]# ls /usr/local/nginx/
conf html logs sbin
[root@localhost nginx-1.6.2]# cd /root/桌面
[root@localhost 桌面]# /usr/local/nginx/sbin/nginx -t //检查语法
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost 桌面]# /usr/local/nginx/sbin/nginx //启动nginx
[root@localhost 桌面]# /usr/local/nginx/sbin/nginx -s reload //平滑重新加载
[root@localhost 桌面]# netstat -anptu |grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 5825/nginx
[root@localhost 桌面]# vim /usr/local/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream myserver {
server 192.168.4.205:80 max_fails=3 fail_timeout=30s;
server 192.168.4.206:80 max_fails=3 fail_timeout=30s;
}
server {
listen 80;
server_name www.baidu.com;
location / {
root html;
index index.html index.htm;
proxy_pass http://myserver;
proxy_set_header Host $host; //添加
proxy_set_header X-Forwarded-For $remote_addr; //添加
}
}
server {
listen 80;
server_name www.souhu.com;
location / {
root html;
index index.html index.htm;
proxy_pass http://myserver;
proxy_set_header Host $host; //添加
proxy_set_header X-Forwarded-For $remote_addr; //添加
}
}
}
wq
在192.168.4.205(web1服务器) //yum安装httpd1服务器,虚拟主机:baidu,souhu
[root@localhost 桌面]# yum -y install httpd
[root@localhost 桌面]# /etc/init.d/httpd start
[root@localhost 桌面]# vim /etc/httpd/conf/httpd.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin 1441107787@qq.com
DocumentRoot /baidu
ServerName www.baidu.com
ErrorLog logs/baidu.com-error_log
CustomLog logs/baidu.com-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin 1441107787@qq.com
DocumentRoot /souhu
ServerName www.souhu.com
ErrorLog logs/souhu.com-error_log
CustomLog logs/souhu.com-access_log common
</VirtualHost>
wq
[root@localhost 桌面]# /etc/init.d/httpd restart
[root@localhost 桌面]# mkdir /baidu
[root@localhost 桌面]# echo "baidu205" > /baidu/index.html
[root@localhost 桌面]# mkdir /souhu
[root@localhost 桌面]# echo "souhu205" > /souhu/index.html
在192.168.4.206(web2服务器) //yum安装httpd2服务器,虚拟主机:baidu.souhu
[root@localhost 桌面]# yum -y install httpd
[root@localhost 桌面]# /etc/init.d/httpd start
[root@localhost 桌面]# vim /etc/httpd/conf/httpd.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin 1441107787@qq.com
DocumentRoot /baidu
ServerName www.baidu.com
ErrorLog logs/baidu.com-error_log
CustomLog logs/baidu.com-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin 1441107787@qq.com
DocumentRoot /souhu
ServerName www.souhu.com
ErrorLog logs/souhu.com-error_log
CustomLog logs/souhu.com-access_log common
</VirtualHost>
wq
[root@localhost 桌面]# /etc/init.d/httpd restart
[root@localhost 桌面]# mkdir /baidu
[root@localhost 桌面]# echo "baidu206" > /baidu/index.html
[root@localhost 桌面]# mkdir /souhu
[root@localhost 桌面]# echo "souhu206" > /souhu/index.html
在192.168.4.66(客户端) //y客户端测试,访问调度器的百度,对应调度到后面不同服务器的百度页面,访问调度器的搜狐,对应调度到后面不同服务器的搜狐页面,
[root@localhost 桌面]# vim /etc/hosts
127.0.0.1 www.baidu.com www.souhu.com
wq
[root@localhost 桌面]# curl http://www.baidu.com
baidu206
[root@localhost 桌面]# curl http://www.baidu.com
baidu205
[root@localhost 桌面]# curl http://www.baidu.com
baidu206
[root@localhost 桌面]# curl http://www.baidu.com
baidu205
[root@localhost 桌面]# curl http://www.souhu.com
souhu206
[root@localhost 桌面]# curl http://www.souhu.com
souhu205
[root@localhost 桌面]# curl http://www.souhu.com
souhu206
[root@localhost 桌面]# curl http://www.souhu.com
souhu205
如果对运维课程感兴趣,可以在b站上搜索我的账号: 运维实战课程,可以关注我,学习更多免费的运维实战技术视频
猜你喜欢
- 2024-10-12 webserver神器 nginx安装(webmin nginx)
- 2024-10-12 Nginx学习笔记(nginx从入门到实践)
- 2024-09-26 CentOS7搭建nginx环境(centos7搭建http)
- 2024-09-26 CentOS7.3安装配置Nginx教程(centos7安装详细图解配置ip)
- 2024-09-26 135页阿里云OSS运维基础实战手册,图文结合一看就懂,仅分享2天
- 2024-09-26 Centos 6.5部署nginx+php环境部署
- 2024-09-26 nginx负载均衡配置(nginx负载均衡配置,当前机器宕机)
- 2024-09-26 Openresrt最佳案例 | 第1篇:Nginx介绍
- 2024-09-26 nginx 源码安装并开启gzip静态压缩
- 2024-09-26 记录一次nginx升级,支持ipv4和ipv6访问https
你 发表评论:
欢迎- 最近发表
-
- Win10 TH2正式版官方ESD映像转换ISO镜像方法详解
- 使用iso镜像升级到Windows 10的步骤
- macOS Ventura 13.2 (22D49) Boot ISO 原版可引导镜像
- 安利一个用ISO镜像文件制作引导U盘的的小工具RUFUS
- CentOS 7使用ISO镜像配置本地yum源
- 用于x86平台的安卓9.0 ISO镜像发布下载:通吃I/A/N、完全免费
- AlmaLinux 9.6发布:升级工具、初步支持IBM Power虚拟化技术
- Rufus写入工具简洁介绍与教程(写入模式)
- 新硬件也能安装使用了,Edge版Linux Mint 21.3镜像发布
- 开源工程师:Ubuntu应该抛弃32位ISO镜像
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)