您的位置:首页 > 理论基础 > 计算机网络

apache的的简单了解。证书与自认证正书的制作以及跳转到https模式

2020-01-31 19:10 851 查看

vim /etc/sysconfig/selinux
中改为disabbled在更改后要关机重启
##关闭selinux
#1.apache
#企业中常用的web服务,用来提供http://(超文本传输协议)
#2.apache的安装部署
yum install httpd -y ##apache软件下载
yum install -y httpd-manual ##apache的手册的下载
systemctl start httpd
systemctl enable httpe
firewall-cmd --permanent --add-service=http ##apache的根目录,默认发布目录
firewall-cmd --reload
firewall-cmd --liset-all

/var/www/html ##apache的根目录,默认发布目录
/var/www/index.html ##apache的默认发布文件
vim /var/www/html/index.html
< h1>hello westos< /h1>
wq保存退出
##测试 http://172.25.254.2 ####用自己的浏览器查看所发布的内容
**# http://172.25.254.2/manual **####查看apache手册

#3.apache的基础信息
#主配置目录 /etc/httpd/conf
#主配置文件 /etc/httpd/conf/httpd.conf
#主配置目录 /etc/httpd/conf.d
#主配置文件 /etc/httpd/conf.d/*.conf
默认发布目录 /var/www/html
默认发布文件 index.html
默认发布端口 80

修改默认端口
vim /etc/httpd/conf/httpd.conf
Listen 8080 ##修改默认端口为8080
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload

修改默认发布文件:
163 < IfModule dir_module>
164 DirectoryIndex index.html
165 < /IfModule>

#######默认的发布文件就是访问apache时没有指点文件名时默认访问的文件
vim /etc/httpd/conf/httpd.conf
164 DirectoryIndex westos index.html ##当westos不存在时访问这个index.html
#######修改默认发布目录
119 DocumentRoot “/westos/html”
123 <Directory “/westos”>
124 Require all granted
125 < /Directory>
126 #

#####访问控制
vim /etc/httpd/conf/httpd.conf
<Directory “/var/www/html/westos”>
Order Allow,Deny ####调整Allow与Deny的顺序,电脑以后面的给比前面的有限级别高
Allow from All
Deny from 172.25.254.2
< /Directory>

systemctl restart httpd #####重启服务后通过浏览器可以看到除了172.25.254.2访问不了外其他的主机都可以访问

###指定用户访问

htpasswd -cm westosuser admin ###这里是在建立可访问的用户admin
htpasswd -m westosuser admin1 #####新建立用户将‘c’去掉不去的话就会覆盖前一个用户
vim /etc/httpd/conf/httpd.conf
<Directory “/var/www/html/westos”>
AuthUserFile /etc/httpd/conf/westosuser
AutherType basic
AuthName “ddffsafda”
Require user admin
< /Directory >
########通过不同的域名访问同一个ip
vim /etc/httpd/conf.d/default.html ######添加而配置文件
<VirtualHost default *:80> #####默认的第一个域名页面
DocumentRoot /var/www/html ####路径
CustomLog logs/default.log combine ######日志存放地点
< /VirtualHost>

<VirtualHost *:80> #######第二个域名配置文件
ServerName news.westos.com
DocumentRoot /var/www/news
CustomLog logs/news.log combine
< /VirtualHost>

<Directory /var/www/news>
Require all granted
< /Directory>
<VirtualHost *:80> #######第三个域名的配置文件
ServerName music.westos.com
DocumentRoot /var/www/music
CustomLog logs/music.log combine
< /VirtualHost>

<Directory /var/www/music>
Require all granted
< /Directory>
wq ###保存退出
systemctl restart httpd

mkdir /var/www/music #####建立所要发布的信息目录
mkdir /var/www/news
vim /var/www/music/index.html
vim /var/www/news/index.html
############注意默认的发布文件是indx.html。如果你在/var/www/music、/var/www/news,中建立的文件名不是index.html而是其他的名字。网站会自动在/etc/www中寻找index.html文件从而使实验失败。
#######在本地的解析中添加域名
vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

172.25.254.254 classroom.example.com
172.25.254.250 content.example.com
172.25.254.100 www.westos.com music.westos.com news.westos.com
##########添加完毕后可用本机浏览器访问三个不同的域名,但他们对应同一个ip

~

# php与 cgi

vim /var/www/html/index.php

<?php ##php不能比丢不然打不开网页 phpinfo(): ?>

yum install -y php ##在/etc/httpd/conf.d中自动会生成php.conf

systemctl restart httpd ##重起打开网页可浏览到php网页
#cgi

mkdir /var/www/html/cgi
vim index.cgi ##在ip加httpd中自带的手册中找到cgi进入其中进行复制第一个cgi程序
#1/usr/bin/perl
print “Content-type: text/html\n\n”;
print “Hello,World”;
chmod +x index.cgi #给与程序运行的权限。并进行运行程序
root@desktop html]# mkdir /var/www/html/cgi
[root@desktop html]# ls
cgi index.html index.php westos
[root@desktop html]# cd cgi
[root@desktop cgi]# vim index.cgi
[root@desktop cgi]# chmod +x index.cgi ####赋予执行权限
[root@desktop cgi]# ./index.cgi
Content-type: text/html

Hello, World.[root@desktop cgi]#
可将程序改为date
#!/usr/bin/perl
print “Content-type: text/html\n\n”;
print

date
;
结果
[root@desktop cgi]# vim index.cgi
[root@desktop cgi]# ./index.cgi
Content-type: text/html

2019年 08月 10日 星期六 19:03:04 EDT
打开网页我们可以看到其中输出的仍是程序代码

为让打开网页可以看到执行程序所输出的时间所以需要根据httpd的手册中查找相关程序,并予以写如配置文件
vim /etc/httpd/conf.d/default.conf
< VirtualHost default:80>
DocumentRoot /var/www/html
CustomLog logs/default.log combined
< /VirtualHost>

<Directory “/var/www/html/cgi”>
Options +ExecCGI
AddHandler cgi-script .cgi

[root@desktop cgi]# systemctl restart network [root@desktop cgi]# systemctl restart httpd ###必须注意要重起网络和htpd

####http与https
#####免费ssl
[root@desktop cgi]# systemctl stop firewalld.service ##关闭防火墙
[root@desktop cgi]# systemctl status firewalld.service ###防火墙情况
firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled) ##已关闭
Active: inactive (dead) since 六 2019-08-10 20:06:54 EDT; 4s ago
Main PID: 473 (code=exited, status=0/SUCCESS)

[root@desktop cgi]# yum install -y mod_ssl ###下载ssl
[root@desktop conf.d]# systemctl restart httpd ###重起服务后可以看到端口开启了
[root@desktop conf.d]# netstat -tnlp |grep :443
tcp6 0 0 :::443 ::? LISTEN 5866/httpd
我们可以通过浏览器看到我们的相关的免费证书

######现在开始作对证书进行自己签名。我们在之后要删除证书和清理缓存。我们继续自签名证书
[root@desktop conf.d]# yum install -y crypto-utils ##下载软件
######生成网站钥匙下来根据自己的情况选择不做说明########
[root@desktop conf.d]# genkey music.westos.com #####生成认证的钥匙
/usr/bin/keyutil -c makecert -g 1024 -s “CN=music.westos.com, OU=linux, O=westos, L=Xi’an, ST=shaanxi, C=CN” -v 1 -a -z /etc/pki/tls/.rand.8283 -o /etc/pki/tls/certs/music.westos.com.crt -k /etc/pki/tls/private/music.westos.com.key
cmdstr: makecert

cmd_CreateNewCert
command: makecert
keysize = 1024 bits
subject = CN=music.westos.com, OU=linux, O=westos, L=Xi’an, ST=shaanxi, C=CN
valid for 1 months
random seed from /etc/pki/tls/.rand.8283
output will be written to /etc/pki/tls/certs/music.westos.com.crt
output key written to /etc/pki/tls/private/music.westos.com.key

Generating key. This may take a few moments…

Made a key
Opened tmprequest for writing
/usr/bin/keyutil Copying the cert pointer
Created a certificate
Wrote 882 bytes of encoded data to /etc/pki/tls/private/music.westos.com.key
Wrote the key to:
/etc/pki/tls/private/music.westos.com.key [###钥匙成功对网站生成#########
[root@desktop conf.d]# vim /etc/httpd/conf.d/ssl.conf ######换掉ssl自带的钥匙
100 #SSLCertificateFile /etc/pki/tls/certs/localhost.crt
101 SSLCertificateFile /etc/pki/tls/certs/music.westos.com.crt
107 #SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
108 SSLCertificateKeyFile /etc/pki/tls/private/music.westos.com.key
推出保存可通过网页观看。可以看到我们自己做的签名证书

####由于登陆时是用域名登陆的如果前面不加https时不会转到安全的模式下因此我们要进行网页重写,使得不加https时域名可####以直接调转到https模式下,网页更加安全
#####我们基于统一ip不同域名进行这项测试
[root@desktop conf.d]# vim default.conf ###配置文件
<VirtualHost *:443>
Servername login.westos.com
DocumentRoot /var/www/login/html
CustomLog logs/login.log combined
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/music.westos.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/music.westos.com.key

<Directory “/var/www/login/html”>
Require all granted

<VirtualHost :80>
Servername login.westos.com
RewriteEngine on
RewriteRule ^(/.)$ https://%{HTTP_HOST}$1 [redirect=301]

[root@desktop conf.d]# mkdir /var/www/login/html -p ##建立新域名的目录
[root@desktop conf.d]# vim /var/www/login/html/index.html ##网页内容
[root@desktop conf.d]# vim /etc/hosts ###添加域名
[root@desktop conf.d]# systemctl start httpd

在浏览器上输入刚才建立的新域名,页面会自动加载到https模式下保证网页安全

#^(/.*)$表示客户在浏览器中输入的所有字符
#1表示(/.∗)1表示 ^(/.*)1表示(/.∗) 的值
*# redirect=301表示转换时永久
#%{HTTP_HOST}表示客户请求主机

  • 点赞
  • 收藏
  • 分享
  • 文章举报
weixin_45466471 发布了47 篇原创文章 · 获赞 0 · 访问量 955 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: