安装配置
软件包:httpd
服务端口:80/tcp(http) 443/tcp(https, http + ssl)
配置文件:/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/*.conf
/etc/httpd/conf.d/welcome.conf//默认测试页面,建议删除
[root@node1 ~]# yum -y install httpd
[root@node1 ~]# tree /etc/httpd/
/etc/httpd/
|-- conf
| |-- httpd.conf
| `-- magic
|-- conf.d
| |-- README
| |-- proxy_ajp.conf
| `-- welcome.conf
|-- logs -> ../../var/log/httpd
|-- modules -> ../../usr/lib/httpd/modules
`-- run -> ../../var/run
[root@node1 ~]# vim /etc/httpd/conf/httpd.conf
### Section 1: Global Environment
ServerRoot "/etc/httpd"//Apache安装目录
PidFile run/httpd.pid//pid文件
Listen 80//监听的端口
# Dynamic Shared Object (DSO) Support // /etc/httpd/modules/
LoadModule auth_basic_module modules/mod_auth_basic.so
Include conf.d/*.conf//包含/etc/httpd/conf.d/*.conf
User apache//运行Apache的用户
Group apache//运行Apache的组
### Section 2: 'Main' server configuration
ServerAdmin root@localhost
#ServerName www.example.com:80
DocumentRoot "/var/www/html"//站点主目录
DirectoryIndex index.html index.php //设置网站首页
### Section 3: Virtual Hosts
Apache配置示例
[root@node1 html]# pwd
/var/www/html
[root@node1 html]# cat index.html
welcome to zhangyunming
[root@node1 html]# service httpd start
启动 httpd: [确定]
[root@node1 html]# chkconfig httpd on
[root@node1 html]# ps auxf | grep httpd |grep -v 'grep'
root 32731 0.0 1.1 10092 2912 ? Ss 13:12 0:00 /usr/sbin/httpd
apache 32732 0.0 0.8 10092 2056 ? S 13:12 0:00 \_ /usr/sbin/httpd
apache 32733 0.0 0.8 10092 2056 ? S 13:12 0:00 \_ /usr/sbin/httpd
apache 32734 0.0 0.8 10092 2056 ? S 13:12 0:00 \_ /usr/sbin/httpd
apache 32735 0.0 0.8 10092 2056 ? S 13:12 0:00 \_ /usr/sbin/httpd
apache 32736 0.0 0.8 10092 2056 ? S 13:12 0:00 \_ /usr/sbin/httpd
apache 32737 0.0 0.8 10092 2056 ? S 13:12 0:00 \_ /usr/sbin/httpd
apache 32738 0.0 0.8 10092 2056 ? S 13:12 0:00 \_ /usr/sbin/httpd
apache 32739 0.0 0.8 10092 2056 ? S 13:12 0:00 \_ /usr/sbin/httpd
[root@node1 html]# netstat -tnlp |grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 32731/httpd
[root@node1 html]# netstat -an |grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 192.168.0.2:80 192.168.0.40:55410 TIME_WAIT
tcp 0 0 192.168.0.2:80 192.168.0.40:55411 TIME_WAIT
tcp 0 0 192.168.0.2:80 192.168.0.40:55412 TIME_WAIT
tcp 0 0 192.168.0.2:80 192.168.0.195:1038 TIME_WAIT
[root@node1 ~]# elinks -dump 192.168.0.2
welcome to zhangyunming.
基于用户家目录发布网<IfModule mod_userdir.c>
UserDir public_html
</IfModule>
service httpd restart
useradd yun
useradd ming
mkdir /home/yun/public_html
mkdir /home/ming/public_html
chmod 755 /home/yun /home/ming
echo "This is yun's home" >> /home/yun/public_html/index.html
echo "This is ming's home" >> /home/ming/public_html/index.html
firefox 浏览器测试
http://192.168.0.1/~robin
http://192.168.0.1/~zorro
[root@node1 ~]# elinks --dump http://localhost/~yun 文本测试方法:
This is yun's homepage
[root@node1 ~]# elinks --dump http://localhost/~ming
This is ming's homepage
别名方式发布
Alias /aaa "/home/yun/public_html"
<Directory "/home/yun/public_html">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Alias /bbb "/home/ming/public_html"
<Directory "/home/ming/public_html">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
本机测试
[root@node1 html]# elinks --dump http://localhost/aaa
This is yun's homepage
[root@node1 html]# elinks --dump http://localhost/bbb
This is ming's homepage
基于用户验证的访问控制
[root@node1 ~]# vim /home/robin/public_html/.htaccess
authname "hello,welcom to my homepage"
authtype basic
authuserfile "/home/robin/public_html/.htpasswd"
require valid-user
~
[root@node1 ~]# htpasswd -c /home/robin/public_html/.htpasswd wang
New password: 123456
Re-type new password:123456
Adding password for user wang
[root@station51 ~]# /etc/init.d/httpd restart
停止 httpd: [确定]
启动 httpd: [确定]
用firefox 测试: http://192.168.1.116/aaa 输入用户名aaa 密码:123456