马哥博客作业第十九周

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

server{
listen 80   ;
server_name www.magedu.org;

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

 

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

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

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

nginx 服务器:10.0.0.105

yum install nginx -y

systemctl enable --now nginx 

vim /etc/nginx/nginx.conf



http{
  include /etc/nginx/conf.d/*.conf upstream webserver { least_conn; server
10.0.0.106; server 10.0.0.107; } }

  vim /etc/nginx/conf.d/web.conf

  server {
     listen 80;
     server_name www.magedu.org;
     location / {
     index index.html index.htm;
     root /var/www/html;
    }
  location /web {
      index index.html index.htm;
      proxy_pass http://webserver/;
       }

  }

apache1 10.0.0.106
yum install -y httpd 

systemctl enable --now httpd

echo 10.0.0.106 > /var/www/html/index.html

apache1 10.0.0.107
yum install -y httpd 

systemctl enable --now httpd

echo 10.0.0.107 > /var/www/html/index.html

  

原文地址:https://www.cnblogs.com/huangguangrui/p/13808960.html