WEB服务器之apache
安装配置软件包: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//默认测试页面,建议删除
# yum -y install httpd
# 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
# 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配置示例
Apache配置示例
# pwd
/var/www/html
# cat index.html
welcome to zhangyunming
# service httpd start
启动 httpd: [确定]
# chkconfig httpd on
# ps auxf | grep httpd |grep -v 'grep'
root 327310.01.1100922912 ? Ss 13:12 0:00 /usr/sbin/httpd
apache 327320.00.8100922056 ? S 13:12 0:00\_ /usr/sbin/httpd
apache 327330.00.8100922056 ? S 13:12 0:00\_ /usr/sbin/httpd
apache 327340.00.8100922056 ? S 13:12 0:00\_ /usr/sbin/httpd
apache 327350.00.8100922056 ? S 13:12 0:00\_ /usr/sbin/httpd
apache 327360.00.8100922056 ? S 13:12 0:00\_ /usr/sbin/httpd
apache 327370.00.8100922056 ? S 13:12 0:00\_ /usr/sbin/httpd
apache 327380.00.8100922056 ? S 13:12 0:00\_ /usr/sbin/httpd
apache 327390.00.8100922056 ? S 13:12 0:00\_ /usr/sbin/httpd
# netstat -tnlp |grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 32731/httpd
# 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
# elinks -dump 192.168.0.2
welcome to zhangyunming.
基于用户家目录发布网
UserDir public_html
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
# elinks --dump http://localhost/~yun 文本测试方法:
This is yun's homepage
# elinks --dump http://localhost/~ming
This is ming's homepage
别名方式发布
Alias /aaa "/home/yun/public_html"
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
Alias /bbb "/home/ming/public_html"
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
本机测试
# elinks --dump http://localhost/aaa
This is yun's homepage
# elinks --dump http://localhost/bbb
This is ming's homepage
基于用户验证的访问控制
# vim /home/robin/public_html/.htaccess
authname "hello,welcom to my homepage"
authtype basic
authuserfile "/home/robin/public_html/.htpasswd"
require valid-user
~
# htpasswd -c /home/robin/public_html/.htpasswd wang
New password: 123456
Re-type new password:123456
Adding password for user wang
# /etc/init.d/httpd restart
停止 httpd: [确定]
启动 httpd: [确定]
用firefox 测试: http://192.168.1.116/aaa 输入用户名aaa 密码:123456
页:
[1]