Linux-apache阿帕奇

apache


1.apche

企业中常用的web服务,用来提供http://(超文本传输协议)
Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩充,将Perl/Python解释器编译到服务器中。同时Apache音译为阿帕奇,是北美印第安人的一个部落,叫阿帕奇族,在美国的西南部。也是一个基金会的名称、一种武装直升机等等。

2.apache的安装部署
yum install httpd -y(配置好yum源进行安装 这里就不再多说了)


yum install httpd-manual


systemctl start httpd
systemctl enable httpd
systemctl stop firewlld
systemctl disable firewalld

测试   http://172.25.254.100
 http://172.25.254.100/manual


#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


#
默认安全上下文:httpd_sys_content_t


#
程序开启默认用户: apache
#apache
日志:  /etc/httpd/logs/*



修改默认端口:
vim /etc/httpd/conf/httpd.conf
43 Listen 8080     ##
修改默认端口为
8080

这时候再用本来默认的80端口访问 发现访问失败了


尝试用8080端口发现访问成功




修改默认发布文件:
默认发布文件就是访问apache时没有指定文件名称时默认访问的文件
这个文件可以指定多个,有访问顺序

 vim /etc/httpd/conf/httpd.conf
164     DirectoryIndex index.htmltest.html    ##
index.html不存在时访问test.html


之后我们删除掉/var/www/html/index.html 建立一个test.html 在test.html中写入我是test啊???之后果然可以发现原来的index.html被删除后果然去访问这个test.html了 表明默认的发布文件修改成成功




修改默认发布目录:
120 DocumentRoot "/www/html"
120 DocumentRoot "/www/html"
121 <Directory "/www">
122         Require all granted
123 </Directory>


semanage fcontext -a -t httpd_sys_content_t '/www(/.*)?'
storecon -RvvF /www/(这里我们必须修改更改目录的文件上下文与原来默认的发布目录一致)




我们在修改后的默认发布目录/www/html/index.html 中写入了HELLO 我们看一下是否修改成功



4.apache的虚拟主机
vim /etc/httpd/conf.d/adefault.conf(这里加了个a 开头 为了让系统首先读取默认文件 系统看文件的首字母巨鼎读取顺序的)
<VirtualHost _default_:80>
    DocumentRoot"/var/www/html"
    CustomLog"logs/www.westos.com.log" combined
</VirtualHost>


vim /etc/httpd/conf.d/linux.conf
<VirtualHost *:80>
    ServerName linux.westos.com #
指定站点名称
    DocumentRoot"/var/www/virtual/linux.westos.com/html/" #
站点默认发布目录
    CustomLog"logs/linux.westos.com.logs" combined       #
站点日志combined标示四种日志的集合

</VirtualHost>
<Directory "/var/www/virtual/linux.westos.com/html/">
    Require all granted
</Directory>


vim /etc/httpd/conf.d/c.conf
<VirtualHost *:80>
    ServerName c.westos.com
    DocumentRoot"/var/www/virtual/c.westos.com/html/"
    CustomLog"logs/c.westos.com.logs" combined
</VirtualHost>
<Directory "/var/www/virtual/c.westos.com/html/">
    Require all granted
</Directory>


建立好目录与文件的写入






测试:
在测试主机中作好本地解析
vim /etc/hosts
172.25.254.100 c.westos.com linux.westos.com

 整体如下所示


分别访问www.westos,com c.westos.com linux.westos.com (写入的index.html的内容可参考上图)






5.apache
内部的访问控制
1.
针对与主机的访问控制
  5 <Directory"/var/www/html/test">
  6         Order deny,allow       ##
列表读取顺序,后读取的列表会覆盖限度去内容的重复部分

  7         Allow from 172.25.254.44
  8         Deny from all
  9 </Directory>

这里我们禁止了172.25.254.100主机的访问


 我们用172.25.254.82访问


但是用172.25.254.100访问 发现果然被禁止了



2.用户方式的访问控制

htpasswd -cm    /etc/httpd/userpass annie(创建用户并且加密给上密码 )
htpasswd -m     /etc/httpd/userpass  riven(这里不能用-cm否则原来创建的用户会被覆盖的)




vim adefault.conf
 10 <Directory"/var/www/html/admin">
 11         AuthUserFile /etc/httpd/userpass
 12        AuthName "Please inputyour name and password"
 13         AuthType basic
 14         #Require        user admin
 15         Require valid-user
 16 </Directory>

之后我们就可以登陆172.25.254.100/admin查看了 可以看到我们被告知必须用用户登陆


登陆之后才可以看到文件的 内容



6.apache支持的语言

1.html
2.php
vim /var/www/html/index.php
<?php
    phpinfo();
?>

yum install php -y


systemctl restart httpd (之后还是需要重启服务再进行测试)

测试
172.25.254.100/index.php


3.cgi
mkdir -p /var/www/html/cgi
semanager fcontent -a -t httpd_sys_script_exec_t '/var/www/html/cgi(/.*)?'
restorecon -RvvF /var/www/html/cgi/
vim /var/www/html/cgi/index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;(查看时间的脚本)

chmod +x /var/www/html/cgi/index.cgi
/var/www/html/cgi/index.cgi #
执行下脚本确保脚本运行正常(查看时间)


vim adefatul.conf
 17 <Directory"/var/www/html/cgi">
 18         Options +ExecCGI
 19         AddHandler cgi-script .cgi
 20 </Directory>


systemctl restart httpd 


之后我们就可以进行测试啦


刷新可以看到时间变化



7.https


yum install crypto-utils -y

yum install mod_ssl -y


genkey www.annie.com


接下来这里我们选择1024字节的加密


加密开始这时候我们在键盘上乱打 加密进度就会前进 直至百分之100完成


之后我们选择不把证书发给CA进行认证


接下来我们进行证书相关内容的书写



安全证书创建成功后会出现这些信息 我们可以看看到 .crt 和 .key


vim /etc/httpd/conf.d/ssl.conf (之后在这里我们把证书的内容*.crt *.key写进ssl.conf这个配置文件中)

101 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
109 SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key

之后这里我们就可以用https://172.25.254.100查看这个安全证书了


安全证书的内容如下所示



8设定https虚拟主机并设定网页重写

vim /etc/httpd/conf.d/login.conf
  1 <VirtualHost *:443>
  2         ServerName login.westos.com
  3         DocumentRoot/var/www/html/virtual/login.riven.com/html
  4         CustomLog "logs/login.logs"combined
  5         SSLEngine on
  6         SSLCertificateFile/etc/pki/tls/certs/www.riven.com.crt
  7         SSLCertificateKeyFile/etc/pki/tls/private/www.riven.com.key
  8 </VirtualHost>
  9 <Directory"/var/www/html/virtual/login.riven.com/html">
 10         Require all granted
 11 </Directory>
 12 <VirtualHost *:80>
 13         ServerName login.riven.com
 14         RewriteEngine On
 15         RewriteRule ^(/.*)$https://%{HTTP_HOST}$1 [redirect=301]
 16 </VirtualHost>

文件的内容


设置好解析


建立好目录


测试结果可以看到



^(/.*)$     ##客户在浏览器地址栏中输入的所有字符
https://    ##
强制客户加密访问
%{HTTP_HOST}    ##
客户请求主机
$1      ###"$1"
标示 ^(/.*)$的值
[redirect=301]  ##
临时重写 302永久转换


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值