yum httpd安装详解:1.安装httpd
2.关闭selinux,iptables程序:
1
2
| [iyunv@localhost ~]# service iptables stop
[iyunv@localhost ~]# setenforce 0
|
3.查看下当前系统80端口是否被占用:
1
2
3
4
5
6
7
| [iyunv@localhost ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::22 :::*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 100 127.0.0.1:25 *:*
[iyunv@localhost ~]#
|
httpd基本配置和应用:
主配置文件:/etc/httpd/conf/httpd.conf 分段配置文件:/etc/httpd/conf.d/*.conf
服务脚本:/etc/rc.d/init.d/httpd
脚本的配置文件:/etc/sysconfig/httpd
模块文件目录:/etc/httpd/modules --> /usr/lib64/modules
主程序文件:/usr/sbin/httpd (prefork)
/usr/sbin/httpd.worker (worker) /usr/sbin/httpd.event (event)
日志文件目录:/var/log/httpd
Access_log:访问日志文件 Error_log:错误日志 站点文档目录:/var/www/html
4.启动httpd:
1
2
3
4
5
| [iyunv@localhost ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using ::1 for ServerName
[ OK ]
[iyunv@localhost ~]#
|
启动时的报错信息:是无法当前使用主机的主机名。没有问题可以忽略。
而且此时的80端口已经启动监听,可以用浏览器来访问:
1
2
3
4
5
6
7
8
| [iyunv@localhost logs]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 100 127.0.0.1:25 *:*
[iyunv@localhost logs]#
|
成功访问测试页面,因为没有主页,把403的页面定位在welcome.conf页面:
修改welcome.conf文件就会出来系统内部文件页面系统:
1
2
3
| [iyunv@localhost conf.d]# ls
README welcome.conf.bak
[iyunv@localhost conf.d]#
|
修改之后复制一个文件进去会显示:
5.httpd主配置文件:
配置文件分割为3端: 1
2
3
4
5
| [iyunv@localhost conf.d]# grep "Section" /etc/httpd/conf/httpd.conf
### Section 1: Global Environment
### Section 2: 'Main' server configuration
### Section 3: Virtual Hosts
[iyunv@localhost conf.d]#
|
注意:Main server 和 Virtual hosts 不能同时启用:默认没有启动虚拟主机。
1.指定监听地址和端口:
1:省略ip表示本机所有可用ip地址; 2:可以指定多次,用于指明多个不同端口。 1
2
3
4
5
6
7
8
9
10
| # Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, in addition to the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses (0.0.0.0)
#
#Listen 12.34.56.78:80
Listen 80
Listen 8080
|
2.持久连接:
持久连接:建立后每个资源获取结束不会断开连接,而继续下去到结束; 断开: 数量:100 时间:60秒 1
2
3
4
5
6
7
8
9
10
11
12
13
14
| KeepAlive Off
#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100
#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 15
|
非持久:每个资源单独专用连接获取:
3.MPM多处理模块:并发请求响应模型
/etc/sysconfig/httpd:修改模块地方。 httpd -l:查看静态模块 httpd -m:查看动态模块 httpd -t -D DUMP_MODULES
1
2
3
4
5
6
7
8
9
| prefock:
<IfModule prefork.c> //如果加载了这个模块,就实现一下配置,一个条件化模块加载
StartServers 8 //服务在启动时默认启动几个子进程
MinSpareServers 5 //最小空闲进程数量
MaxSpareServers 20 //最大空闲进程数量
ServerLimit 256 //限制MaxClients 最大活动进程
MaxClients 256 //最大并发量,就是同时访问数量
MaxRequestsPerChild 4000 //每个子进程最多能处理的请求数量,处理够数量后就被kill然后重新启动
</IfModule>
|
1
2
3
4
5
6
7
8
9
| worker:
<IfModule mpm_worker_module>
StartServers 2 //服务器启动时建立的子进程数,默认值是"3"。
MaxClients 150 //允许同时伺服的最大接入请求数量(最大线程数量)
MinSpareThreads 25 //最小空闲进程
MaxSpareThreads 75 //最大空闲进程
ThreadsPerChild 25 //每个子进程建立的常驻的执行线程数
MaxRequestsPerChild 0 //设置每个子进程在其生存期内允许伺服的最大请求数量.0是不会结束。
</IfModule>
|
4.模块加载:DSO
loadMoudle <moudle_name><moudle_path>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_alias_module modules/mod_authn_alias.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
|
5.定义main,主页文件路径
DocumentRoot "/var/www/html"
6.站点访问路径控制:
文件系统路径: <Directory “/PATH/TO?SOMEDIR”> </Directory>
7.directory定义:
Optiones i. Indexes:当访问的路径下没有主页面,也没有资源,就用列表形式呈现。 ii. 如果有某页面文件指向DocumentRoot之外的文件,照样显示文件。 iii. None 关闭 iv. All 都启用 Order:检查次序 Order Allow Deny 明确Allow才允许,其他为Deny
8.定义默认主页面
DirectoryIndex index.html index.html.var 自左而右的次序
9.路径别名:
比如:Alias /bbs/ “/web/bbs/htdocs/” 如果访问bbs 则直接指向web/bbs/htdocs
10.默认字符集:
AddDefaultCharset UTF-8
11.基于用户的访问控制:
质询:www-Authenticate:服务器用401拒绝客户请求,说明需要用户提供用户名,密码,淡出对话框。 认证:客户端用户填入账号密码,再次发送请求。 比如:/var/www/html/iamges 不能访问
1.定义配置: 1
2
3
4
5
6
7
8
| <Directory "/var/www/html/iamges">
Options Indexes
AllowOverride None
AuthType Basic
AuthName "iamges"
AuthUserFile /etc/httpd/users/.htpasswd
Require valid-user
</Directory>
|
2.htpasswd 1
2
3
4
5
| [iyunv@localhost ~]# mkdir /etc/httpd/users
[iyunv@localhost ~]# htpasswd -c -m /etc/httpd/users/.htpasswd hzm
New password:
Re-type new password:
Adding password for user hzm
|
3.测试访问
12.虚拟主机:
http三种类型虚拟主机:ip,端口,域名。 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| <VirtualHost 192.168.112.128:80>
ServerName www.a.com
ServerAlias a.com
DocumentRoot /vhosts/a.com/
</VirtualHost>
<VirtualHost 192.168.112.128:80>
ServerName www.b.com
ServerAlias b.com
DocumentRoot /vhosts/b.com/
</VirtualHost>
[iyunv@localhost users]# curl www.a.com
<h1>www.aww.a.com</h1>
[iyunv@localhost users]# curl www.b.com
<h1>www.b.com</h1>
[iyunv@localhost users]#
|
|