sass

负载均衡

所有工作均在root权限下执行

1.准备工作16.04

俩台apache服务器,一台lnmp(nginx)服务器

apache2:
apt-get install apache2

2.在apache服务器下放入html文档

放置目录:

/var/www/html

俩个服务器分别写入index.html,内容分别为:

this is server one

this is server two

3.在windows下检测俩台apache是否安装成功!

打开对应的ip地址,会输出this isserver one 或者 this is server two

4.配置nginx

1.打开目录/etc/nginx/

cd /etc/nginx/

2.备份nginx.conf

cp nginx.conf nginx.conf.back

3.打开nginx.conf并编辑

vim nginx.conf
加入俩台apache的ip地址:
upstream site {
    server 192.168.3.82:8040;
    server 192.168.3.82:8041;
} 
配置域名 
server {
    listen 8080;
    server_name {nginx的域名};
}
配置目录及加入那俩台服务器
location / {
    root html;//这个地方是文档放置目录,默认打开的目录
    index index.html index.htm;
    proxy_pass http://site;//site及代表上面的绑定的那俩个apache服务器
}

4.调试nginx检测是否有错

nginx -t //没有错误则 第一行显示ok  否则报出错误位置

4.配置完成,保存wq,重启nginx

service nginx restart

5.配置windows端的域名

windows->system32->drives->etc->hosts

6.在浏览器输入域名,没刷新一次换一次服务器

会依次显示:this isserver one
           this is server two

ok,负载均衡搭建成功!

负载均衡实现动静分离

1.准备工作

俩台存储php,java,js等程序(动态服务器)
一台存储静态文件{html、css、images}(静态服务器)

2.为动态服务器安装解析程序,本次仅展示安装php,并在目录下写入php程序。

apt-get install php
apt-get install libapache2-mod-php7.0 将php与apache2整合

3.配置nginx

cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.back
打开nginx.conf
vi /etc/nginx/nginx.conf

4.开始配置

在http{}里面加入:
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {  
    proxy_pass  http://192.168.x.x;//如果是nginx做静态服务器的话  格式如下:root 文档路劲 
    #expires定义用户浏览器缓存的时间为3天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力.  
    expires 3d;  
} 

5.保存,调试nginx,成功后重启nginx

6.测试

浏览器里输入nginx域名/test.html
会打开静态服务器下的静态文件test.html
浏览器里输入nginx域名/test.php
会打开动态服务器下的动态文件test.php

你可能感兴趣的:(sass)