RHEL7.2Linux下搭建简易的web服务器

一.WEB服务器(1)

搭建一个基于http://www.zuoye.com:11111或者http://wwww.zuoye.com:11111访问的web网站,网站首页在/www/zuoye/,内容为homework。
注意:防火墙和selinux(关闭防护墙与selinux条件下)
[root@lemon ~]# mkdir -p /www/zuoye----创建网站首页目录
[root@lemon ~]# echo homework >/www/zuoye/index.html—写入网页内容
[root@lemon ~]# cd /etc/httpd/conf.d/
[root@lemon conf.d]# vim vhost1.conf—编辑虚拟主机配置文件
RHEL7.2Linux下搭建简易的web服务器_第1张图片

AllowOverride none
Require all granted

Listen 11111

DocumentRoot /www/zuoye
ServerName www.zuoye.com
ServerAlias wwwww.zuoye.com

[root@lemon ~]# vim /etc/hosts-----编辑缓存文件
加入192.168.20.128 www.zuoye.com
192.168.20.128 wwww.zuoye.com
[root@lemon ~]# systemctl stop firewalld—关闭防火墙
[root@lemon ~]# setenforce 0—设置selinux
[root@lemon ~]# getenforce
Permissive
[root@lemon ~]# systemctl restart httpd—重启http服务
访问测试:
[root@lemon ~]# curl www.zuoye.com:11111
homework
[root@lemon ~]# curl wwww.zuoye.com:11111
homework

Windows: C:\Windows\System32\drivers\etc\hosts----缓存文件
加入
192.168.20.128 www.zuoye.com
192.168.20.128 wwww.zuoye.com
物理windows本地主机浏览器测试:
RHEL7.2Linux下搭建简易的web服务器_第2张图片

RHEL7.2Linux下搭建简易的web服务器_第3张图片

二.WEB服务器(2)

搭建一个基于https://www.zuoye.com:22222访问的web网站,网站首页在/www/https/,内容为zuoye,可以根据https://www.zuoye.com:22222/mimi访问到的信息为mimi,该网站的实际内容在/usr/local/secret,该网站的内容只有用户xiaoming能够查看
[root@lemon ~]# yum install httpd -y—装包
[root@lemon ~]# yum install mod_ssl -y—装包
[root@lemon certs]# cd /etc/pki/tls/certs/
[root@lemon certs]# make limao.crt—创建证书
[root@lemon ~]# vim /etc/httpd/conf.d/vhost.conf—编辑配置文件

AllowOverride none
Require all granted

Listen 22222

SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5:!SEED:!IDEA
SSLCertificateFile /etc/pki/tls/certs/limao.crt
SSLCertificateKeyFile /etc/pki/tls/certs/limao.key
DocumentRoot /www/https
ServerName www.zuoye.com
alias /mimi /usr/local/secret


authtype basic
authname “please login:”
authuserfile /etc/httpd/lemon
require user xiaoming

[root@lemon ~]# htpasswd -c /etc/httpd/lemon xiaoming—添加用户xiaoming
New password:
Re-type new password:
Adding password for user xiaoming
[root@lemon ~]# htpasswd -c /etc/httpd/lemon lm—添加用户lm
New password:
Re-type new password:
Adding password for user lm
[root@lemon ~]# systemctl stop firewalld—关闭防火墙
[root@lemon ~]# setenforce 0设置selinux
[root@lemon ~]# getenforce
Permissive
[root@lemon certs]# systemctl restart httpd—重启服务
Enter SSL pass phrase for www.zuoye.com:443 (RSA) : *****
[root@lemon ~]# mkdir /www/https—创建目录
[root@lemon ~]# echo zuoye >/www/https/index.html—写入网页内容
[root@lemon ~]# mkdir /usr/local/secret—创建目录
[root@lemon ~]# echo mimi >/usr/local/secret/index.html—写入网页内容
本地测试:
在 /etc/hosts 和windows C:\Windows\System32\drivers\etc\hosts加入
192.168.20.128 www.zuoye.com
①本地测试:
[root@lemon ~]# curl --insecure https://www.zuoye.com:22222
zuoye
[root@lemon ~]# curl --insecure https://www.zuoye.com:22222/mimi/ -u xiaoming
Enter host password for user ‘xiaoming’:
mimi
[root@lemon ~]# curl --insecure https://www.zuoye.com:22222/mimi/ -u lm
Enter host password for user ‘lm’:

401 Unauthorized

Unauthorized

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

②本地物理windows主机测试 ![在这里插入图片描述](https://img-blog.csdnimg.cn/2019120122551664.bmp) ![在这里插入图片描述](https://img-blog.csdnimg.cn/20191201225528943.bmp?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjU0MDk5OQ==,size_16,color_FFFFFF,t_70) ![在这里插入图片描述](https://img-blog.csdnimg.cn/2019120122553132.bmp?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjU0MDk5OQ==,size_16,color_FFFFFF,t_70)

你可能感兴趣的:(服务器搭建)