apache网页服务器

Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器,可以在大多数计算机操作系统中运行,由于其多平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩展,将Perl/Python等解释器编译到服务器中。

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

apache安装和部署

yum install  httpd  -y   #安装apache软件
systemctl  start  httpd    #启动服务
systemctl  enable  httpd   #开机启动
firewall-cmd --permanent  --add-server=http  #火墙永久添加http服务
firewall-cmd  --reload  #重新加载火墙策略
firewall-cmd   --list-all   #列出火墙信息


/var/www/html  #apache的默认发布目录
/var/www/html/index.html   #默认发布文件
vim  /var/www/html/index.html 
#编辑   <h1>westos</h1>

测试部署

在同一网段可以ping通的主机上
http://172.25.254.66  #会显示之前输入的westos
如果安装yum install httpd-manuual   软件
#可以查询apache服务的手册
http://17225.254.66/manual   #可以查看apache的说明

apache的配置文件以及主配置目录

/etc/httpd/conf   #主配置目录
/etc/httpd/conf/httpd.conf    #主配置文件
/etc/httpd/conf.d  #子配置目录
/etc/httpd/conf.d/*.conf  #子配置文件
index.html  #默认发布文件(识别的文件)
默认的端口为80
httpd_sys_content_t   #默认的安全上下文
程序的默认用户为apache
/etc/httpd/logs/*   #apache日志目录

默认端口的修改

vim  /etc/httpd/conf/httpd.conf  
#编辑http主配置文件
默认里面42行   listen 80  
#将80改为8080
systemctl restart httpd   
#重启服务
netstat  -antlupe | grep httpd  
#过滤出httpd的端口
测试:在另一台主机通过ip直接访问访问不到,首先亚看自己的selinux的状态,在火墙上添加8080端口 firewall-cmd --permannet --add-port=8080/tcp 
再次测试:通过ip后面跟:8080  就直接可以访问
semanage port -l  | grep  httpd
#过滤出httpd服务可以使用的端口
 

默认发布文件

默认发布文件目录   /var/www/html
默认的发布文件index.html
自己建立一个westos.html
测试:如果访问ip看到的时默认的发布文件,如果在ip后面加/westos.html则就可以访问到
vim    /etc/httpd/conf/httpd.conf  
#编辑主配置文件164行:他是默认的发布文件修改为westos.html  
systemctl restart httpd
#重新启动服务
再次通过访问ip看到的文件就是westos.html
如果两者都写入的默认访问前面的那个
 

修改默认的发布目录

mkdir  -p  /westos/html   
vim  /westos/html/index.html
#新建目录编辑文件
vim    /etc/httpd/conf/httpd.conf 
#修改配置文件 120行添加 DocumentRoot  "/westos/html"  注释掉之前的发布目录
在120行后面添加目录的授权
#  <Directory /westos/html>
#          Require  all granted
#  </Directory>
测试:输入ip地址就可以查看/westos/html/的文件

如果selinux开启的话就不可以访问需要修改安全上下文
ls  -Zd  /var/www/html   #查看默认的安全上下文
semanage  fcontext -a  -t  http_sys_content_t  '/westos/html(/.*)?'
#修改建立目录的安全上下文
restorecon      -RvvF   /westos/html  #重新加载生效
测试:selinux开启状态下也可以访问

一个虚拟apache有多个域名

vim  /etc/httpd/conf.d/vhost.conf
#编辑子配置目录下的文件vhost.conf
<VirtualHost _default_:80>   #虚拟主机默认端口80
 	    DocumentRoot /var/www/html   #共享目录
        CustomLog logs/default.log  combined  #日志目录及其类型   
</VirtualHost>
在测试主机里面做本地解析  vim  /etc/hosts 
# 172.25.254.66  www.westos.com news.westos.org  music.westos.org
#编辑子配置目录下的文件vhost.conf
<VirtualHost *:80>
         ServerName news.westos.org
         DocumentRoot /var/webvirt/westos.org/new/html
        CustomLog logs/news.log  combined
 </VirtualHost>
 
 <VirtualHost *:80>
         ServerName music.westos.org
         DocumentRoot /var/webvirt/westos.org/music/html
        CustomLog logs/music.log  combined
 </VirtualHost>
 
 <Directory /var/webvirt>
         Require  all granted
 </Directory>
mkdir -p  /var/webvirt/wetsos.org/{news,music}/html
vim   /var/webvirt/wetsos.org/news/html/index.html
vim   /var/webvirt/wetsos.org/music/html/index.heml
#建立目录编辑文件 
重启服务 
测试:访问www.westos.com news.wetsos.org music.westos.org  会显示出自己编辑的内容

内部的访问(指定访问)

vim /etc/httpd/conf.d/vhost.conf 
#编辑文件
 <Directory  "/var/www/html">
    	 Order allow,deny
       	 Allow from all
     	 Deny  from 172.25.254.11
 </Directory>
 #allow代表白名单,deny代表黑名单  order后面那个在前先读那个后面的会覆盖前面的 
 重启服务
     	 

用户访问设置

用户认证信息   /etc/httpd/
 htpasswd  -cm /etc/httpd/.htpassfile  admin #新建用户用-cm
 htpasswd -m /etc/httpd/.htpassfile  admin1  #建立第二个用户用 -m
 cat  .apache_auth # 查看用户信息
 vim /etc/httpd/conf.d/vhost.conf  #编辑文件
 <Directory  "/var/www/html">
  #       Order allow,deny  注释之前的实验
  #       Allow from all
  #       Deny  from 172.25.254.11
          AuthUserfile   /etc/httpd/.htpassfile 认证的文件类型
          AuthType        basic  #认证类型
          AuthName        "Please input username and password!!" # 认证名称
          Require         valid-user  #允许所有的用户 (user admin)只允许admin用户访问
 </Directory>   
 重启服务
测试:通过浏览器访问输入用户名和密码则可以登陆
      

https加密访问

yum  install mod_ssl.x86_64  -y   #安装https
yum  install crypto-utils.x86_64  -y       #添加插件(命令)
genkey fangyuan.com #生成自己的锁和钥匙
vim /etc/httpd/conf.d/ssl.conf  
#编辑文件写入自己的钥匙和密码,在文件的101行,和108行分别添加公钥私钥
重启服务
测试:通过ip访问已经生成了自己的锁

https虚拟主机以及网页的重写

 mkdir -p    /var/webvirt/westos.org/login/html/
 vim      /var/webvirt/westos.org/login/html/index.html
 #建立目录以及文件
 vim  /etc/httpd/conf.d/https.conf
 #编辑文件
 <VirtualHost *:443>  #建立一个端口443虚拟主机
         ServerName login.westos.com
         DocumentRoot /var/webvirt/westos.org/login/html #默认发布目录
         CustomLog logs/login.log  combined
         SSLEngine on  #开启密钥认证
         SSLCertificateFile /etc/pki/tls/certs/fangyuan.com.crt #私钥
         SSLCertificateKeyFile  /etc/pki/tls/private/fangyuan.com.key #公钥     
 </VirtualHost>
 <VirtualHost *:80>  #建立80端口的虚拟主机
         ServerName login.westos.org
         RewriteEngine on   #将网页重写功能开启
         RewriteRule ^(/.*)$  https://%{HTTP_HOST}$1  [rediect=301] #永久的转换
 </VirtualHost>
 重启服务
 测试:浏览器login.westos.org 转入到https://login.westos.com
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值