web集群第二次作业

1、源码安装nginx,并提供服务脚本。
配置服务启动脚本
2、配置基于域名的虚拟主机
3. 配置nginx基于用户和地址的访问控制。
配置基于地址的访问控制:
基于基于用户的访问控制
4.配置nginx rewrite,要求如果访问不存在的任意网页都重定向到错误页面,错误页面内容自行定义。

1源码安装的一些依赖

yum install -y pcre-devel
yum install -y openssl-devel
yum install gcc gcc-c++ make -y

开始安装

[root@localhost ~]# wget -c http://tengine.taobao.org/download/tengine-2.3.0.tar.gz
[root@localhost tengine-2.3.0]# make
[root@localhost tengine-2.3.0]# make install
[root@localhost tengine-2.3.0]# /usr/local/nginx/sbin/nginx

配置服务启动脚本

[root@localhost tengine-2.3.0]# vi  /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c   /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true


[Install]
WantedBy=multi-user.target    

启动niginx

[root@localhost tengine-2.3.0]# systemctl daemon-reload
[root@localhost tengine-2.3.0]# systemctl  start nginx

浏览器访问192.168.159.111

 2配置基于域名的服务器

配置环境

[root@localhost nginx]# for i in blog bbs
> do
> mkdir html/$i
> done
[root@localhost nginx]# for i in blog bbs
> do
> echo "$i test page." > html/$i/index.html
> done

添加模块配置文件

[root@localhost nginx]# vi /usr/local/nginx/conf/nginx.conf
http {
    #gzip  on;
   include /usr/local/nginx/conf.d

创建文件目录

[root@localhost nginx]# mkdir  /usr/local/nginx/conf.d

配置文件添加虚拟主机部分,创建虚拟主机

[root@localhost nginx]# vi /usr/local/nginx/conf.d/vhost.conf
server {
listen  80;
server_name  bbs.test.com;
location / {
    root   html/bbs;
    index  index.html index.htm;
        }
}

server {
listen  80;
server_name  blog.test.com;
location / {
    root   html/blog;
    index  index.html index.htm;
        }

在另一台设备上配置hosts域名信息

[root@localhost ~]# vi /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.159.111   bbs.test.com   blog.test.com
[root@localhost ~]# curl  bbs.test.com
[root@localhost ~]# curl  blog.test.com

3. 配置nginx基于用户和地址的访问控制

在虚拟主机中配置基于地址的访问控制

[root@localhost nginx]# vi /usr/local/nginx/conf.d/vhost.conf
erver {
listen  80;
server_name  bbs.test.com;
location / {
    root   html/bbs;
    index  index.html index.htm;
    deny  192.168.159.111;
    allow 192.168.159.9/24;
    deny  all;
        }
   location  /nginx_status {
        stub_status on;
        accexx_log off;
 }
}

在配置拒绝访问的192.168.159.111的主机上访问测试

[root@localhost nginx]# curl  bbs.test.com
curl: (7) Failed connect to bbs.test.com:80; Connection refused

在配置允许访问的192.168.159.112的主机访问

 

    inet 192.168.159.112/24 brd 192.168.159.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fea1:9926/64 scope link 
       valid_lft forever preferred_lft forever
[root@hlt ~]# curl bbs.test.com
<!DOCTYPE html>
<html>
<head>
<title>Welcome to tengine!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值