第十九周作业

1、实现永久重定向,当用户访问 www.magedu.org 这个域名时我想让他跳转到 www.magedu.com 的主页面,请写出配置过程

vim /apps/nginx/conf.d/pc.conf

location / {
  root /data/nginx/html/pc;
  index index.html;
  rewrite / https://www.magedu.com permanent;
}

2、rewrite案例-判断文件是否存在,要求:当用户访问到公司网站的时输入了一个错误的 URL ,可以将用户重定向至 www.magedu.com 官网首页。请写出配置过程

vim /apps/nginx/conf.d/pc.conf

location / {
  root /data/nginx/html/pc;
  index index.html;
  if (!-e $request_filename) {
    rewrite .* http://www.magedu.org/index.html;
  }
}

3、用 nginx 做一个代理服务器,server_name 为 www.magedu.org,代理后端两台 apache 服务器。并且要求使用最少连接调度算法实现,这样才能做到后端 apache 服务器的压力大到均衡

在两台机器分别安装apache服务器
10.0.0.1
yum install httpd -y
echo "web1 10.0.0.1" > /var/www/html/index.html
systemctl enable --now httpd
10.0.0.2
yum install httpd -y
echo "web2 10.0.0.2" > /var/www/html/index.html
systemctl enable --now httpd

vim /apps/nginx/conf/conf.d/pc.conf

http {

upstream webserver {
  least_conn;
  server 10.0.0.1:80 weight=1 fail_timeout=5s max_fails=3;
  server 10.0.0.2:80 weight=1 fail_timeout=5s max_fails=3;
}
server {
  listen 80;
  server_name www.magedu.org
  location / {
    index index.html index.php;
    root /data/nginx/html/pc;
  }
  location /web {
    index index.html;
    proxy_pass http://webserver/;
  }
}

}

posted @ 2020-11-04 13:36  Jay11143  阅读(96)  评论(0)    收藏  举报