Httpd
将httpd启动脚本加入chkconfig列表中
vim /etc/init.d/httpd
#!/bin/bash ----- 修改第一行声明shell类型
# chkconfig:2345 55 25
2345代表启动级别 55代表开机后第55个启动 25关机时候第25关闭
# description:wo shi apache
chkconfig --add httpd ---- 将其加入chkconfig列表
chkconfig --list httpd --- 验证
http配置文件/usr/local/apache2/conf/httpd.conf
修改主机名/etc/sysconfig/network
HOSTNAME=www.benet.com
ServerRoot"/usr/local/apache2" ----apache根目录
Listen 80 ---- 监听端口
LoadModule php5_module modules/libphp5.so --php模块加载
AddType application/x-httpd-php .php ---php应用
User daemon --- 启动用户名称
Group daemon --- 组名称
ServerName www.benet.com ---- 主机名称
ServerAdmin [email protected] --- 管理员邮箱
DocumentRoot"/usr/local/apache2/htdocs" --- 主页存放位置
DirectoryIndex index.html index.php --- 主页索引文件名
ErrorLog "logs/error_log" --- 错误日志
LogLevel warn --- 日志级别
CustomLog "logs/access_log"common --- 访问日志和格式
Include conf/extra/httpd-vhosts.conf --- 指定虚拟主机的配置文件
<Directory /> ---- 对根目录的安全限制
Options FollowSymLinks --- 支持软连接
AllowOverride None --- 不允许修改配置信息
Order deny,allow ---访问策略先deny后allow
Deny from all ---- 拒绝所有人访问
</Directory>
<Directory"/usr/local/apache2/htdocs">
Order allow,deny
Allow from 172.16.0.0/16
</Directory>
apache命令的路径优化
ln -s /usr/local/apache2/bin/* /usr/bin
httpd -t 检查配置文件语法
apachectl -t 检测语法错误
htpasswd -c /usr/local/apache2/conf/.webpwdtom
输入密码确认密码
htpasswd /usr/local/apache2/conf/.webpwdjerry
输入密码确认密码
vim /usr/loacl/apache2/conf/httpd.conf
<Directory"/usr/local/apache2/htdocs">
Order allow,deny
Allow from 172.16.0.0/16 192.168.0.0/24
AuthName "huan ying guang lin" -- 登录信息
AuthType Basic --- 浏览器通用的登录窗口
AuthUserFile /usr/local/apache2/conf/.webpwd -- 加密文件位置
require valid-user --- 只允许授权用户登录
</Directory>
/etc/init.d/httpd restart ---重启服务验证
apache三个虚拟主机的建立
基于ip 基于端口基于域名
基于域名的虚拟主机
vim /usr/local/apache2/conf/httpd.conf
Include conf/extra/httpd-vhosts.conf 指定虚拟主机的配置文件
vim/usr/local/apache2/conf/extra/httpd-vhosts.conf ---修改虚拟主机配置文件
<Directory "/var/www/html">
Order allow,deny
Allow from all
</Directory>
NameVirtualHost 192.168.0.1:80 ---开启域名虚拟主机功能
<VirtualHost 192.168.0.1:80>
DocumentRoot "/var/www/html/benetcom"
ServerName www.benet.com
</VirtualHost>
<VirtualHost 192.168.0.1:80>
DocumentRoot "/var/www/html/accpcom"
ServerName www.accp.com
</VirtualHost>
/etc/init.d/httpd restart --- 重启生效
mkdir -p /var/www/html/benetcom/var/www/html/accpcom
echo "woshibenet" >/var/www/html/benetcom/index.html
echo "woshiaccp" >/var/www/html/accpcom/index.html
xp验证修改hosts文件
192.168.0.1 www.benet.com
192.168.0.1 www.accp.com
基于端口的虚拟主机
vim/usr/local/apache2/conf/extra/httpd-vhosts.conf ---修改虚拟主机配置文件
<Directory "/var/www/html">
Order allow,deny
Allow from all
</Directory>
<VirtualHost 192.168.0.1:80>
DocumentRoot"/var/www/html/benetcom"
ServerName www.benet.com
</VirtualHost>
<VirtualHost 192.168.0.1:8080>
DocumentRoot "/var/www/html/accpcom"
ServerName www.accp.com
</VirtualHost>
vim /usr/local/apache2/conf/httpd.conf
listen 8080
/etc/init.d/httpd restart