http:
提供
web
服务
port
:
80 tcp
协议
version
:
1.1
无状态的不保存用户账号
cookie
可以保存用户认证信息
响应码:
url
重定向
301 302
4 zaz
暂时性错误
5
永久性错误
服务器
web
软件:
httpd
lighttpd nginx
反向加速较好
--
》开源轻量级
静态页面性能较好
IIS WEBSPHERE TOMCAT RESIN
httpd
:
Apache
网站:
www.apache.org
主配置文件:
/etc/httpd/conf/httpd.conf
服务脚本:
/etc/init.d/httpd
网页默认页面:
/var/www
网页静态默认目录:
/var/www/html/
网站主页:
/var/www/html/index.html
索引:
index
在主页面不存在时
会把
/var/www/html
的页面都显示出来
httpd
支持的页面格式:
.html .jsp
主配置文件:
vim /etc/httpd/conf/httpd.conf
DocumentRoot "/var/www/html"
定义网页文件根目录
<Directory />
容器定义目录属性的
Options Indexes
索引
FollowSymLinks
跟踪符号链接
一般要关掉
AllowOverride None
是否允许覆盖
acl
控制列表
off
不认证
默认为
None
Order allow,deny
定义
acl
的
先允许后拒绝
Order deny,allow
Allow from all
Deny from 192.168.0.65
</Directory>
# UserDir disable
启用在普通用户家目录建立网页文件
UserDir public_html
目录名
ErrorLog logs/error_log
定义错误日志文件
CustomLog logs/agent_log combined
定义访问日志文件
在修改默认网页
DocumentRoot
目录:
1
、关闭
selinux
2
、在不关闭
selinux
时要修改目录的标签
加入目录为
/www
ls -Z /www
chcon -R --reference=/var/www/html /www
启用在普通用户家目录建立网页文件:主配置文件修改
# UserDir disable
关闭
UserDir public_html
启用
su - student
mkdir public_html
vim piblic_html/index.html
chmod a+x /home/student
setenforce 0
service httpd restart
测试
:http://192.168.0.124/~student
目录名不为
public_html
时要修改目录标签为
user_u:object_r:httpd_sys_content_t
创建路径别名:主配置文件下添加
Alias /bbs "/tmp/bbs"
路径一般要对应
mkdir /bbs /tmp/bbs
vim /tmp/bbs/index.html
service httpd restart
测试:
http://192.168.0.124/bbs
注意:再修改主配置文件时都要重启服务
其前最好测试主配置文件语法的正确性
测试服务
httpd -t
配置文件语法的正确性
或者
service httpd configtest
service httpd restart
或
reload
ACL
启用用户认证访问
提供账号和密码
conf
下的
httpd.conf
修改:
<Directory "/www">
AllowOverride AuthConfig
AuthName "jjjjj"
显示信息
AuthType basic (local)
使用本地的文件当做数据库
AuthUserFile /home/bob/.passwd
密码信息文件
require user jing king (
允许的用户名
)
</Directory>
htpasswd -cm
创建密码文件
第二次不用
c
参数
htpasswd -cm /home/bob/.passwd jing
htpasswd -c /home/bob/.passwd king
简单定义多用户:
require valid-user
将用户加入密码文件
/home/bob/.passwd
即可
对单个目录做认证:
创建
.htaccess
文件
将用户认证的信息添加里面,目录为要认证的目录
ssl
认证:
协议版本
sslv1 sslv2
ssl
配置文件:
/etc/httpd/conf.d/ssl.conf
SSLProtocol all -SSLv2
协议
SSLVerifyClient require
验证客户端证书
默认没开启
基于
https
的方式访问网站:
安装模块
yum install mod_ssl
配置文件:
/etc/httpd/conf.d/ssl.conf
做自签
CA
mkdir /etc/httpd/ssl
cd /etc/httpd/ssl
openssl genrsa 1024 > httpd.key
openssl req -new -kry httpd.key -out httpd.csr
openssl ca -in httpd.csr -out httpd.crt
vim /etc/httpd/conf.d/ssl.conf
SSLCertificateFile /etc/httpd/ssl/httpd.crt
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key
DocumentRoot "/www"
ServerName www.a.com:443
httpd -t
service httpd restart
测试:
https://192.168.0.124
https
不支持基于主机名的虚拟主机
CGI
格式的脚本:支持
cgi
格式的网页
/etc/httpd/conf/httpd.conf
默认启用
虚拟主机:
web
服务器,同时提供多个网站服务,即多个主机
,
一个主机,占用一个排它性的资源
一个主机:
基于
ip
:
192.168.0.124:80
192.168.0.125:80
基于端口:一个
ip
使用多个不同端口实现多个网站服务
基于主机名:多个域名同时指向一个端口,较为常用
www.a.com:80
www.b.com:80
配置虚拟主机:基于
ip
的
mkdir /var/www/html/www1 /var/www/html/www2
vim /var/www/html/www1/index.html
vim /var/www/html/www2/index.html
取消中心主机
DocumentRoot
注释掉
<VirtualHost 192.168.0.124:80>
DocumentRoot /var/www/html/www1
ServerName www1.ilinux.org
ErrorLog /var/log/httpd/www1.err
定义错误日志的
CustomLog /var/log/httpd/www1.access common(combind
日志类型
)
<Directory "/var/www/html/www1">
对目录定义
acl
Order allow,deny
Allow from 192.168.0.0/24
</Directory>
</VirtualHost>
<VirtualHost 192.168.0.125:80>
DocumentRoot /var/www/html/www2
ServerName www2.ilinux.org
ErrorLog /var/log/httpd/www2.err
CustomLog /var/log/httpd/www2.access common
</VirtualHost>
基于端口的:
将
<VirtualHost 192.168.0.124:80>
修改即可
<VirtualHost 192.168.0.124:8080>
listen 80
listen 8080
添加
service httpd restart
测试:
http://192.168.0.124
http://192.168.0.124
:
8080
基于主机名的:
nameVirtualHost 192.168.0.124:80
开启
与下面对应
ip
可以为
*
<VirtualHost 192.168.0.124:80>
<VirtualHost 192.168.0.124:80>
Apache
压力测试
-c
并发连接数
-n
发起的请求
ab -c 100 -n 3000 http://www1.ilinux.com/index.html
php
:
Personal Home Page
网站:
www.php.net
PHP
超文本预处理器
解释性的语言
做
web
开发
php+httpd
一块工作
php
做成
apache
的模块
redhat
的默认方式
php
做成一个单独的应用程序服务器
php+httpd
配置:
yum install mod_php
配置文件:
/etc/httpd/conf.d/php.conf
DirectoryIndex index.php
主网页文件
修改主文件
mv /var/www/html/www1/index.html /var/www/html/index.php
vim index.php
<h1> test </h1>
<?php
phpinfo();
?>
service httpd restart