欢迎光临
我们一直在努力

Apache服务的示例分析

本篇文章为大家展示了Apache服务的示例分析,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

Apache HTTP SERVER

Apache软件基金会的一个开放源代码的网页服务器软件

curl -I 查看网站的网页服务器类型

实验测试之前注意向发起访问请求的主机添加域名解析/etc/host

一、安装httpd

yum install httpd

systemctl start httpd

systemctl enable httpd #开机启动

firewall-cmd  –permanent –add-service=http #将http服务添加至防火墙列表中

firewall-cmd  –reload

firewall-cmd  –permanent –add-service=https #将https服务添加至防火墙列表中

firewall-cmd  –reload

修改http的主配置文件修改默认设置

/etc/httpd/conf/httpd.conf

42 Listen 80#修改http服务的默认网络端口

119 DocumentRoot "/www/html"#修改http服务的默认发布目录

120 <Directory "/www/html">

121     Require all granted

122 </Directory>

167 <IfModule dir_module>

168     DirectoryIndex webtest index.html#默认发布文件,先读前者,前者不可用再读后者#

169 </IfModule>

firewall-cmd –add-port=8080/tcp

systemctl restart httpd

mkdir /www/html/webtest

selinux标签与默认发布目录一致

ls -Z /var/www/

semanage fcontext -a -t httpd_sys_content_t “/www(/.*)?”

restorecon -vvFR /www

二、虚拟主机

一台主机为多个网站提供服务

vim /etc/httpd/conf.d/default.conf

<Virtualhost _default_:80>

        Documentroot /www/html

        Customlog "logs/default.log" combined#指定日志

</Virtualhost>

vim /etc/httpd/conf.d/news.conf

<Virtualhost *:80>

        Servername news.laosiji.com

        Serveralias news#设置别称

        Documentroot /www/laosiji.com/news

        Customlog "logs/news.log" combined

</Virtualhost>

<Directory "/www/laosiji.com/news">

        Require all granted

</Directory>

vim /etc/httpd/conf.d/xxx.conf

mkdir -p /www/laosiji.com/news

vim /www/laosiji.com/news/webtest#与前面设置的文件名称一致

三、授权指定用户访问

首先新建一个发布目录作为测试目录

mkdir -p /www/laosiji.com/admin/webtest

htpasswd -cm /etc/httpd/htpasswd admin    #再次添加用户时注意,选项为-m,否则之前的信息会被覆盖

New password:

Re-type new password:

会生成加密密码文件/etc/httpd/htpasswd

<Directory "/www/laosiji.com/film/admin">

        Authuserfile "/etc/httpd/htpasswd"

        Authtype basic

        Authname "Please input username and password"

        Require user admin#或者设置为valid-user所有授权用户可登陆

</Directory>

四、自定义自签名证书

yum install crypto-utils mod_ssl

genkey laosiji.com #主机名,生成证书

选择next

有几种密钥规格供选择

生成密钥中    #生成缓慢时可以敲击键盘或移动鼠标

选择no不向CA发送验证请求

选择next

填写一些信息(注意主机名不要写错)

vim /etc/httpd/conf.d/login.conf#新建login用于测试

mkdir /www/laosiji.com/login

<Virtualhost *:443>

        Servername login.laosiji.com

        Serveralias login

        Documentroot /www/laosiji.com/login

        Customlog "logs/login.log" combined

        SSLEngine on

        SSLCertificateFile /etc/pki/tls/certs/laosiji.com.crt

        SSLCertificateKeyFile /etc/pki/tls/private/laosiji.com.key

</Virtualhost>

<Directory "/www/laosiji.com/login">

        Require all granted

</Directory>

<VirtualHost *:80>#网页重定向

servername login.laosiji.com

rewriteengine on

rewriterule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]

</VirtualHost>

systemctl restart httpd

vim /www/laosiji.com/login/webtest#写一份测试文本

Welcome log in

打开浏览器写入login.laosiji.com

选择Add Excetion

选择Confirm Security Exception

得到证书网页即可正常显示

上述内容就是Apache服务的示例分析,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注云搜网行业资讯频道。

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。