apache

来源:互联网 发布:a星寻路算法教程 编辑:程序博客网 时间:2024/06/11 21:22

APACHE 的基本配置

apache的安装

yum install httpd -ysystemctl start httpd systemctl stop firewalld systemctl enable httpd systemctl disable firewalld 

apache的基本信息

1.apache的默认发布文件index.html2.apache的配置文件/etc/httpd/conf/httpd.conf/etc/httpd/conf.d/*.conf3.apache的默认发布目录/var/www/html4.apache的默认端口80

apache的环境配置

[root@localhost Desktop]# yum search httpd[root@localhost Desktop]# yum install httpd.x86_64 -y[root@localhost Desktop]# systemctl start httpd[root@localhost Desktop]# cd /var/www/html/[root@localhost html]# ls[root@localhost html]# vim index.html[root@localhost html]# cat index.html 

这里写图片描述
此时访问不到里面内容
这里写图片描述
方法*设置火墙策略,允许http通过火墙*
这里写图片描述
重新启动http服务后
这里写图片描述

1.修改默认发布文件

vim /etc/httpd/conf/httpd.conf164     DirectoryIndex westos.htmlsystemctl restart httpd 

2.修改默认发布目录
当selinux是disable状态

vim /etc/httpd/conf/httpd.conf120 DocumentRoot "/westos/www/test"<Directory "/westos/www/test">        Require all granted</Directory>systemctl restart httpd

新建一个mkdir /westos/html

这里写图片描述

当selinux是enforcing状态vim /etc/httpd/conf/httpd.conf120 DocumentRoot "/westos/www/test"<Directory "/westos/www/test">        Require all granted</Directory>systemctl restart httpdsemanage fcontext -a -t httpd_sys_content_t '/westos(/.*)?'restorecon -RvvF /westos

3.apache的访问控制

设定ip的访问
这里写图片描述

vim /etc/httpd/conf/httpd.conf<Directory "/westos/html/">##允许所有人访问目录但是拒绝19主机        Order Allow,Deny        Allow from All        Deny from 172.25.254.19</Directory>
<Directory "/westos/html">       ##只允许19主机访问目录        Order Deny,Allow        Allow from 172.25.254.19        Deny from All   

测试:

设定用户的访问
这里写图片描述

htpasswd -m /etc/httpd/accessuser adminvim /etc/httpd/conf/httpd.conf<Directory "/var/www/html/admin">        AuthUserFile /etc/httpd/accessuser          ##用户认证文件        AuthName "Please input your name and password !!"   ##用户认证提示信息        AuthType basic                      ##认证类型        Require valid-user                  ##认证用户,认证文件中所有用户都可以通过    [Require user admin]                    ##只允许认证文件中admin用户访问,二写一</Directory>

这里写图片描述

这里写图片描述

这里写图片描述

apache的虚拟主机

1.定义
**可以让我们的一台apache服务器在被访问不同域名的时候显示
不同的主页,例如网页里面的子网页。**

2.建立测试页
这里写图片描述

mkdir  virtual/money.westos.com/html -pmkdir  virtual/news.westos.com/html -p

3.配置
这里写图片描述

vim /etc/httpd/conf.d/default.conf  ##位指定域名的访问都访问default<Virtualhost    _default_:80>       ##虚拟主机开启的端口    DocumentRoot "/var/www/html"    ##虚拟主机的默认发布目录    CustomLog "logs/default.log" combined   ##虚拟主机日志</Virtualhost>

vim /etc/httpd/conf.d/news.conf ##指定域名news.westos.com的访问到指定默认发布目录中

4.测试

**在浏览器所在主机中
vim /etc/hosts
172.25.254.119 www.westos.com news.westos.com*
这里写图片描述

这里写图片描述

这里写图片描述

4.网页访问加密

1.https定义
Hyper text transfer protocol over Secure socker layer
通过ssl

2.配置
yum install mod_ssl -y
yum install crypto-utils -y
genkey www.westos.com
/etc/pki/tls/private/www.westos.com.key
/etc/pki/tls/certs/www.westos.com.crt
vim /etc/httpd/conf.d/login.conf
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

这里写图片描述

vim login.conf
这里写图片描述

这里写图片描述

重新启动服务httpd

测试

在客户主机中添加解析
vim /etc/hosts
172.25.254.119 login.westos.com
访问http://login.westos.com 会自动跳转到
https://login.westos.com 实现网页数据加密传输
这里写图片描述

原创粉丝点击