RHCE web服务器与加密web服务器

1.搭建静态网站--基于httpd协议的静态网站

案例:搭建自己的一个web网站

先搞清楚网站资源存放位置 ;  /var/www/html

会在目录下找index.html文件

配置文件在 /etc/httpd/conf.d/

(1)先准备网站目录

    #mkdir /var/www/html/a.org

#vim /var/www/html/a.org/index.html

(2)创建配置文件

#vim  /etc/httpd/conf.d/a.org.conf

<VirtualHost   *:80>        //*代表某机器的IP地址 ,80是httpd的端口号
ServerName   www.a.org       //服务器起个名字
DocumentRoot     /var/www/html/a.org 
</VirtualHost>
<Directory  "/a.org">
Require all granted               // 授权
</Directory>
(3)重启服务

#systemctl restart httpd
 

案例1: 搭建一个web服务器,访问该服务器是显示“hello word!”欢迎界面

分析:1.设置默认访问apache欢迎界面的配置文件是哪个?apache欢迎界面 的具体文件在哪?

配置文件是   /etc/httpd/conf.d/welcome.conf

欢迎界面文件是 /usr/share/httpd/noindex/index.html

2.自己定义的静态页面路径在哪?哪个文件?

路径 /var/www/html /var/www/html/index.html

步骤:#echo hello word > /var/www/html/index.html

           #curl 192.168.76.3

案例2:建立两个基于ip地址访问的网站

要求:1.该网站ip地址的主机位为100,设置DocumentRoot为/www/ip/100,网页内容为:this is 100.

2.该网站ip地址的主机位为200,设置DocumentRoot为/www/ip/200,网页内容为:this is 200.
3.192.168.76.100 ->访问的是100这个网站   192.168.76.200 ->访问的是200这个网站

步骤:1.添加两个ip,分别为192.168.76.100和192.168.76.200

            2.创建两个网页文件的根目录,并定义网页内容

           3.定义基于不同ip地址来访问网站的配置文件

操作:

第一步:

#nmcli connection modify ens33 +ipv4.addresses 192.168.76.100/24 ipv4.gateway 192.168.76.1 ipv4.method manual connection.autoconnect yes
#nmcli connection modify ens33 +ipv4.addresses 192.168.76.200/24
# nmcli connection up ens33
#ip addr                             //查看ip地址

第二步:

# mkdir -pv /www/ip/{100,200}
# echo this is 100 > /www/ip/100/index.html
# echo this is 200 > /www/ip/200/index.html
# setenforce 0        //防火墙临时关闭
# getenforce          //显示当前SELinux的应用模式

第三步:

# vim /etc/httpd/conf.d/host.conf
##在这个文件中编写
<Directory /www>                                //Directory  中说的是权限
AllowOverride none
Require all granted
</Directory>
<VirtualHost 192.168.76.100:80 >
DocumentRoot /www/ip/100
ServerName   192.168.76.100
</VirtualHost>
<VirtualHost 192.168.76.200:80>
DocumentRoot /www/ip/200
ServerName   192.168.76.200
</VirtualHost>

#systemctl restart httpd
#curl 192.168.76.100
#curl 192.168.76.200

案例三:建立两个不同端口访问网站

要求:

1.DocumentRoot为/www/port/80,网页内容为: the port 80.

2.建立一个使用1000端口的网站,设置DocumentRoot为/www/port/1000,网页内容为:the port is 1000.

步骤:1.创建两个文件根目录,并定义内容

           2.定义基于不同端口来访问网站的配置文件

操作:

第一步:

# mkdir -pv /www/port/{80,1000}
# echo the port is 80 > /www/port/80/index.html
# echo the port is 1000 > /www/port/1000/index.html

第二步:

# vim /etc/httpd/conf.d/host.conf
##在文件中编写
<Directory /www>
AllowOverride none
Require all granted
</Directory>

<VirtualHost 192.168.76.3:80>
DocumentRoot /www/port/80
ServerName  192.168.76.3
</VirtualHost>
Listen 1000
<VirtualHost 192.168.76.3:1000>
DocumentRoot /www/port/1000
ServerName 192.168.76.3
</VirtualHost>

# systemctl restart httpd
#  curl 192.168.76.3
# curl 192.168.76.3:1000

案例四:建立两个基于域名访问的网站

要求:1.新建一个网站,域名为www.ceshi.com ,设置DocumentRoot 为/www/name,网页内容为this is test。

2.新建一个网站,域名为www.rhce.com ,同时可通过www.ce.com访问,设置DocumentRoot为/www/ce,网页内容为today is first day of class。

步骤:

要求1:

# mkdir -pv /www/name
# echo this is test! > /www/name/index.html
# vim /etc/httpd/conf.d/host.conf
<Directory /www>
AllowOverride none
Require all granted
</Directory>
<VirtualHost 192.168.76.3:80>
DocumentRoot /www/name
ServerName  www.ceshi.com
</VirtualHost>

然后在C:\Windows\System32\drivers\etc中找到hosts文件   ,在里面加入ip地址和网站

 在浏览器访问

 要求2:

# mkdir -pv /www/ce
# echo today is first day of class > /www/ce/index.html
# vim /etc/httpd/conf.d/host.conf
<Directory /www/ce>
AllowOverride none
Require all granted
</Directory>
<VirtualHost 192.168.76.100:80>
DocumentRoot /www/ce
ServerName www.rhce.com
</VirtualHost>
<VirtualHost 192.168.76.3:80>
DocumentRoot /www/ce
ServerName www.ce.com
</VirtualHost>
# systemctl restart httpd

然后在C:\Windows\System32\drivers\etc中找到hosts文件   ,在里面加入ip地址和网站。

加密web服务器

也就是http+ssl   =https

什么是ssl?

安全套接层,IETF 就把SSL 标准化。标准化之后SSL被改为 TLS(Transport Layer Security传输层安全协议),也就是说,ssl和tls是一个东西。

ssl协议分为两层:

1.SSL记录协议 (SSL Record Protocol):它建立在可靠的传输协议(如TCP)之上,为高层协议提供数据封装、压缩、加密等基本功能。

2.SSL握手协议(SSL Handshake Protocol):它建立在SSL记录协议之上,用于在实际的数据传输开始前,通讯双方进行身份认证、协商加密算法、交换加密密钥等。(重要最好记住。)

案例:搭建一个加密的web服务

[root@localhost ~]# yum install mod_ssl -y                 //安装ssl
[root@localhost ~]# cd /etc/pki/tls/certs/                  //和下一步都是自己创建一个ca认证
[root@localhost certs]# make jiami.crt  /etc/httpd/conf.d/ssl.conf 
[root@localhost ~]# vim /etc/httpd/conf.d/host.conf          //编辑配置文件
<VirtualHost 192.168.76.123:80>
SSLEngine on                          //启用
SSLProtocol all -SSLv2
 SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5:!SEED:!IDEA   //密码套件,列出允许客户端协商的密码
SSLCertificateFile /etc/pki/tls/certs/jiami.crt       //指定认证书的路径
SSLCertificateKeyFile /etc/pki/tls/certs/jiami.key    //指定秘钥文件路径
 DocumentRoot "/home/www/jiami"
ServerName 192.168.76.123
</VirtualHost>
<Directory /www/jiami>
AllowOverride none
Require all granted
</Directory>
[root@localhost orange]# setenforce 0   //把selinux切换成宽容模式
[root@localhost orange]# getenforce     // 查看selinux当前模式       
[root@localhost orange]# systemctl restart httpd

案例2:搭建基与虚拟目录和用户控制的web网站

[root@localhost ~]# htpasswd -c /etc/httpd/mymima xiaoming(-c表示创建)
输入密码
[root@localhost ~]# htpasswd  /etc/httpd/mymima xiaohong
输入密码
[root@localhost ~]# mkdir /usr/local/mysecret
[root@localhost ~]# echo this is my secret > /usr/local/mysecret/index.html
[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf 
<VirtualHost 192.168.76.100:80>
alias /mimi /usr/local/mysecret
servername 192.168.76.100
<Directory /usr/local/mysecret>
authtype basic
authname "please login:"
authuserfile /etc/httpd/mymima
require user xiaoming xiaohong
</Directory>
</VirtualHost>
[root@localhost ~]#systemctl restart httpd

案例3:搭建动态网站  (cgi)

[root@localhost ~]# yum install mod_wsgi -y

[root@localhost ~]# yum install  mod_wsgi -y
[root@localhost ~]# cd /etc/httpd/conf
[root@localhost conf]# vim httpd.conf
在AddHandler cgi-script .cgi .py                //添加.py
[root@localhost cgi-bin]# vim test.py
#! /usr/bin/python2
print("content-type:text/html;charset-utf-8\n")
print("this is my first cgi progrem")
[root@localhost cgi-bin]# chmod -x test.py      //添加执行权限
[root@localhost cgi-bin]# vim /etc/httpd/conf.d/host.conf 
<VirtualHost 192.168.76.80:80>
DocumentRoot /www/cgi-bin
ScriptAlias "/cgi-bin" "/www/cgi-bin"
ServerName 192.168.76.80
<Directory /www/cgi-bin>
allowoverride none
require all granted
</Directory>
</VirtualHost>
[root@localhost cgi-bin]# mkdir /www/cgi-bin
[root@localhost cgi-bin]# cp /var/www/cgi-bin/test.py /www/cgi-bin/
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce


然后再浏览器输入地址/cgi-bin/test.py    验证即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值