http-超文本传输文件之apache

apache


一 apache
企业常用的web服务,用于提供http://(超文本传输协议)

作用:

        Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩充,将Perl/Python解释器编译到服务器中

二 apache的安装部署
yum install httpd -y
yum install httpd-manual(注释)
systemctl start httpd
systemctl enable httpd
systemctl stop firewalld
systemctl disable firewalld

测试  http://172.25.254.141


三 apache的基础信息

主配置目录  :  /etc/httpd/conf


主配置文件: /etc/httpd/conf/httpd.conf
子配置目录: /etc/httpd/conf.d
子配置文件: /etc/httpd/cong.d/*.conf
默认发布目录 : /var/www/html
默认发布文件: index.html
默认端口:  80
默认安全上下文: httpd_sys_content_t
程序开启默认用户: apache
apache日志 : /etc/httpd/logs/*


1) 修改默认端口  
vim /etc/httpd/conf/httpd.conf
43 Linsten 8080 修改默认端口为8080

ss -anutlpe | grep httpd (查看httpd的端口)



2) 修改默认发布文件

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

vim /etc/httpd/conf/httpd.conf
164 DirectoryIndex index.html text.html   当index.html不存在时访问text.html



3)修改默认发布目录

120 DocumentRoot "/www/html"
121 <Directory "/www">
                 Require all granted (所有人都能访问)
123 </Directory>

semanage fcontext -a -t httpd_sys_content '/www(/.*)?(www下的全部东西)'  添加安全上下文
restorecon -RvvF /www/ 刷新安全上下文


四 apache的虚拟主机

分别创建两个虚拟主机

1) mkdir /var/www/virtual/linux.westos.com/html -p

       mkdir /var/www/virtual/c.westos.com/html -p

写入默认发布文件

2) vim /var/www/virtual/linux.westos.com/html/index.html

      vim /var/www/virtual/c.westos.com/html/index.html


3) vim /etc/httpd/conf.d/adefaukt.conf 默认访问目录
<VirtualHost _default_:80>
        DocumentRoot "/var/www/html"
        CustomLog "logs/www.westos.com.log" combined
</VirtualHost>:wq

4)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 站点日志combined标示四种日志类别
</VirtualHost>
<Directory "/var/www/virtnal/c.westos.com/html">
        require all granted
</Directory>


测试

在测试主机中修改本机解析文件
vim /etc/hosts
172.25.254.141 biu.com




五 apache内部的访问控制

1)针对主机的文件

vim /etc/httpd/conf.d/adefault.conf

<VirtualHost _dafault_:80>

DocumentRoot "/var/www/html"

CustomLog "logs/www.westos.com.log" combined

</VirtualHost>

 <Directory “/var/www/html/test”>
                 order allow deny --列表读取顺序,后读取的覆盖先读取的内容
                 Allow frow all
                 Deny frow all  禁止xxx访问
</Directory>



2) 用户方式的访问控制
htpasswd -cm /etc/httpd/userpass admin
htpasswd -m /etc/httpd/userpass admin1  添加新的认证用户(第一次加c 后面不用加c)

vim /var/www/html/admin


vim adefault.conf
<Directory "/var/www/html/admin">
   AuthUserFile /etc/httpd/userpass
   AuthName "Please input your name and password"
   AuthType basic
   Require user admin 针对用户admin

   Require vaild-user 针对有效用户

测试 浏览器输入172.25.254.153/admin


输入172.25.254.153/admin

admin1




六 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

semanage fcontext -a -t httpd_sys_content '/var/www/html/cgi(/.*)?'  添加安全上下文
restorecon -RvvF /var/www/html/cgi刷新安全上下文

vim /var/www/html/cgi/index.cgi


chmod +x /var/www/html/cgi/index.cgi

/var/www/html/cgi/index.cgi   执行脚本,确保脚本正常运行

 

vim adefault.conf

<Directory "/var/www/html/cgi">

Options +ExecCGI

AddHandler  cgi-script .cgi


测试



七 https

含义:

       HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版。即HTTP下加入SSL层,HTTPS的安全基础是SSL,因此加密的详细内容就需要SSL。 它是一个URI scheme(抽象标识符体系),句法类同http:体系。用于安全的HTTP数据传输。https:URL表明它使用了HTTP,但HTTPS存在不同于HTTP的默认端口及一个加密/身份验证层(在HTTP与TCP之间)。这个系统的最初研发由网景公司(Netscape)进行,并内置于其浏览器Netscape Navigator中,提供了身份验证与加密通讯方法。现在它被广泛用于万维网上安全敏感的通讯,例如交易支付方面

1)下载

yum install crypto-utils -y 证书

yum install mod_ssl -y  443端口

genkey 公司名

进入设定界面完成步骤安装



vim /etc/httpd/conf.d/ssl.conf


然后登陆测试,需要下载证书,下载后即可正常登陆

删除证书

点击edit ,选择preferences


然后选择view certificates,从中找出证书即可


八 设定apache虚拟主机并设定网页重写


^(/.*)$ 客户在浏览器地址栏输入的所有字符

http://  强制客户加密访问

%{HTTP_HOST}  客户请求主机

[redirect=301]  临时重写 ,302 表示永久


测试





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值