Apache基本配置
Apache web 服务
1.Apache基本配置
Apache主配置文件:/etc/httpd/conf/httpd.conf
ServerRoot "/etc/httpd" 用于指定Apache的运行目录
Listen 80 监听端口
User apache
Group apache 运行apache程序的用户和组
ServerAdmin root@localhost 管理员邮箱
DocumentRoot "/var/www/html" 网页文件的存放目录
<Directory "/var/www/html">
Require all granted
</Directory> <Directory> 语句块自定义目录权限
ErrorLog "logs/error_log" 错误日志存放位置
AddDefaultCharset UTF-8 默认支持的语言
IncludeOptional conf.d/*.conf 加载其它配置文件
DirectoryIndexindex.html 默认主页名称
(http服务)安装Apache服务

(设定火墙,允许http服务)


查看端口;

在/var/www/html/下创建存放网页文件的文件夹,并写入内容;

修改客户端/etc/hosts
将服务端域名加入本地解析
#ip servername
172.25.254.118 www.westos.com news.westos.com
创建虚拟主机配置文件:
# cat /etc/httpd/conf.d/default.conf
<Virtualhost _default_:80>
documentroot /var/www/html
customlog "logs/default.log" combined #日志存放目录
</Virtualhost>
<Directory /var/www/html>
require all granted #同意所有请求
</Directory>


配置域名为news.westos.com的目录的配置文件
# cat news.conf
<virtualhost *:80>
servername news.westos.com
documentroot /var/www/news
customlog "logs/news.log" combined
</virtualhost>
<directory /var/www/news>
require all granted
</directory>

重启服务 systemctl restart httpd
浏览器访问 www.westos.com 即可访问到虚拟主机/var/www/html/下的文件
news.westos.com 即可访问到虚拟主机/var/www/news/下的文件
2.配置基于用户的身份验证
Apache无格式文件用户身份验证在此配置中,用户账户和密码存储在本地.htpasswd文件中。处于安全原因,该文件不能保存在网站的DocumentRoot中,而应保存在Web服务器不提供服务的一些目录中。特殊的htpasswd命令用于在.htpasswd文件中管理用户。
虚拟主机配置:
l创建Apache密码文件:
# htpasswd -cm /etc/httpd/conf/apacheusr admin
键入密码

修改news.conf配置:

重启服务,并使用浏览器测试访问news.westos.com,在弹出的对话框中输入上述用户名和密码。
浙公网安备 33010602011771号