第19周作业--nginx
1、实现永久重定向,当用户访问 www.magedu.org 这个域名时我想让他跳转到 www.magedu.com 的主页面,请写出配置过程
需提前编译ngx_http_rewrite_module 模块
vim /etc/nginx/nginx.conf
location / {
rewrite / http://www.magedu.com redirect;
}
2、rewrite案例-判断文件是否存在,要求:当用户访问到公司网站的时输入了一个错误的 URL ,可以将用户重定向至 www.magedu.com 官网首页。请写出配置过程
vim /etc/nginx/nginx.conf
....
location / {
...
if ( $scheme = http ){ rewrite / https://$host redirect; } if ( !-e $request_filename ){ rewrite .* http://www.magedu.com; }
}
3、用 nginx 做一个代理服务器,server_name 为 www.magedu.org,代理后端两台 apache 服务器。并且要求使用最少连接调度算法实现,这样才能做到后端 apache 服务器的压力大到均衡
vim /etc/nginx/nginx.conf
http {
upstream web-server{
least_conn;
server IP1;
server IP2;
}
......
server {
listen 80;
server_name www.magedu.org;
location /{
index index.html;
root "/data/nginx/html";
proxy_pass http://web-server/;
}
}

浙公网安备 33010602011771号