apache:服务器软件,简单,速度快,稳定
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
2.http 配置文件
[root@localhost Desktop]# cd /etc/httpd/
[root@localhost httpd]# ls
conf conf.d conf.modules.d logs modules run
conf 主配置文件
Listen 80 #访问端口
DocumentRoot “/var/www/html” #默认访问文件目录 【授权】
DirectoryIndex index.html #默认访问文件名
授权格式:
默认访问文件格式:
3虚拟主机的子配置文件
一台主机的IP可以通过多个域名访问
1)创建域名访问目录
vim hosts
2)编写域名访问文件
root@localhost www]# mkdir news 建立虚拟用户访问录
[root@localhost www]# echo The weather is so good today > news/Linux 写入内容
[root@localhost www]# cat news/linux 查看内容
3)查看安全上下文
[root@localhost conf.d]# ls -Z /var/www/html/index.html
-rw-r–r–. root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/index.html
[root@localhost conf.d]# ls -Z /var/www/news/linux
-rw-r–r–. root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/news/linux
若不一致则要修改
[root@apache html]# semanage fcontext -a -t httpd_sys_content_t ‘/www(/.*)?’
或者关闭selinux
setenforce 0
4虚拟主机配置文件编写
[root@localhost conf.d]# vim news.conf
Servername news.westos.com #访问的域名
Documentroot /var/www/news #域名对应的家目录
customlog “logs/news.log” combined #日志存放位置
require all granted #授予权限
4.用户访问加密
[root@localhost Desktop]# cd /etc/httpd/conf/
[root@localhost conf]# ls
httpd.conf magic
[root@localhost conf]# htpasswd -cm apachuser dch 创建用户{第一个}{-c}
New password: 设立密码
Re-type new password: 重复密码
Adding password for user dch
[root@localhost conf]# ls
apachuser httpd.conf magic
[root@localhost conf]# cat apachuser
dch:apr1hLElLGdk$JEaxT8Ibv8CdY7yOT5S5l0
htpasswd -m apachuser lee 再次创建用户不需要{-c}
New password:
Re-type new password:
Adding password for user lee
[root@localhost conf]# ls
apachuser httpd.conf magic
[root@localhost conf]# cat apachuser
dch:apr1hLElLGdk$JEaxT8Ibv8CdY7yOT5S5l0
lee:apr1OEYnk7Ul$mrLiSjuwEHx3whSJMXxiS1
编写登陆加密所需的配置文件
[root@localhost conf]# vim /etc/httpd/conf.d/news.conf
Authuserfile /etc/httpd/conf/apachuser #用户和密码文件存放位置
Authname “Please enter the passwd”
Authtype basic #文件类型
Require user dch #用户白名单
Require valid-user #允许所有用户
创建访问文件
[root@localhost conf]# mkdir /var/www/news/dch
[root@localhost conf]# touch /var/www/news/dch/file1
[root@localhost conf]# cat /var/www/news/dch/file1
Ni hao HAH
5.添加IP访问权限
[root@localhost conf]# vim /etc/httpd/conf.d/news.conf
Order allow,deny #顺序(允许和否定) #deny,allow 先执行deny的,再执行allow的
allow from 172.25.254.200
5.https加密自定义
1.安装crypto-utils软件包
[root@localhost Desktop]# yum install crypto-utils.x86_64 mod_ssl.x86_64 -y 安装软件包
[root@localhost Desktop]# genkey apache-sever.crt 生成私钥和证书
安装证书及其私钥
[root@localhost Desktop]# yum search mod_ssl
[root@localhost Desktop]# vim /etc/httpd/conf.d/news.conf
[root@localhost Desktop]# systemctl restart httpd.service
本文转自铁骑传说51CTO博客,原文链接:http://blog.51cto.com/ybzbfs/1926849 ,如需转载请自行联系原作者