表示多道处理模块,用于定义当多个用户同时访问,Web
服务器应该如何进行响应,
Global Environment
:全局环境配置,也就是这里面定义的所有的选项具有全局属性Global Environment
: 表示主服务配置段,Virtual Hosts
:虚拟主机段,Global Environment
和Virtual Hosts
不能够同时启用;# [注意空格]
开头的表示都是注释,#
表示的是指令指令的含义:
ServerTokens OS
:表示输出操作系统信息,尽量不显示这里的信息;
ServerRoot "/etc/httpd"
:HTTPD
的工作主目录,强烈建议不要更改;PidFile run/httpd.pid
:进程运行时PID号码;Timeout 60
:TCP三次第一次握手之后,等待用户发起第二次请求的时间;KeepAlive Off
:表示是否使用长连接启用,尽量避免三次握手;MaxKeepAliveRequests 100
:长连接最多使用的请求数量;KeepAliveTimeout 15
:表示长连接超时时间;prefork MPM
:表示多道处理模块,用于定义多个用户发起请求时,Web服务器应该如何进行响应的工作模型;
StartServers 8 //服务器启动需要多少个空闲进程;
MinSpareServers 5 //最小空闲进程;
MaxSpareServers 20 //最大空闲进程;
ServerLimit 256 //下面参数的上限值,需要结束进行,调大这个参数,底下参数的硬限制
MaxClients 256 //表示最大客户端数
MaxRequestsPerChild 4000 //每一个子进程最多相应多少次请求,销毁这个进程;
StartServers 4 //默认启动多少个进程
MaxClients 300 //最多允许多少个用户请求
MinSpareThreads 25 //最小空闲线程
MaxSpareThreads 75 //最大空闲线程
ThreadsPerChild 25 //一个进程生成多少个线程
MaxRequestsPerChild 0 //么一个进程最多相应多少个请求;
[root@server3 conf]# rpm -ql httpd | grep bin
/usr/sbin/apachectl
/usr/sbin/htcacheclean
/usr/sbin/httpd
/usr/sbin/httpd.event
/usr/sbin/httpd.worker
HTTPD
的运行模式# vim /etc/sysconfig/httpd 这个是`httpd`服务启动脚本的配置文件
# HTTPD=/usr/sbin/httpd.worker 大约在第9行;
Listen
:表示监听的端口,一般这个需要更改的次数很多;LoadModule
:用于表示在启动时,加载的模块;User apache
:表示httpd
进程工作的用户;Group apache
:表示httpd
进程工作的组;ServerAdmin root@localhost
:用于写明管理员地址;#ServerName www.example.com:80
://如果不起用这个指令,服务器在启动的时候,会反向解析IP地址如果能够解析成功,就把解析到的主机名当作服务器的名字,否则可能会出错,警告没有主机名使用localhost当作主机名;需要编辑/etc/hosts补充主机名,或者需要使用DNS进行解析;基于主机名的虚拟主机这个是必须启用的;UseCanonicalName Off
:使用正式名称,表示服务器如何实现自我引用的;DocumentRoot "/var/www/html"
:表示文档目录,默认发布目录;URL
路径和本地文件系统路径没有关系URL
相对于DocuentRoot
的路径而言的,如果更改了这个目录,HTTPD
运行的用户必须对于这个目录具有相应的读写权限,并且需要更改对于的访问控制Indexes
:用于将所有的文件列出来,建议关闭,除非是用来下载文件,默认是允许的,需要关闭;Includes
:表示执行服务器段包含(SSI),不安全,建议关闭;SymLinksifOwnerMatch
:表示允许执行执行符号链接,但是连接指向的文本,必须和运行HTTPD的用户是一致的;ExecCGI
:是否允许执行CGI脚本;MultiViews
:内容协商机制,根据客户端来源,语言,文字,判定应该显示那一种网页;All
:表示启用所有选项;AllowOverride None
:表示是否允许下面的控制法则生效;<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
Directory>
里面定义的信息的说明,Options
:用于定义目录被访问的属性,可以包含多个值,多个值之间使用,
隔开,Options
支持以下的选项: index
:表示索引,也就是将DocumentRoot
里面的对应的文件按照索引进行显示,不建议启动index
.如果作为文件下载服务器,那么可以是启用的;FollowSymLinks
:表示是否允许访问年符号连接真正指向的文件,大多数情况下,符号连接和真实文件的路径不一定是是一致的,不安全,影响服务器速度;Includes
:表示是否允许执行服务器包含,例如SSI
服务器包含文件,这个也是不安全的;SymLinksifOwnerMatch
:表示允许执行符号连接,但是执行的属主和属组必须和httpd
的属主和属组匹配;ExecCGI
是否允许执行CGI
;MultiViews
:多功能视图,内容协商机制,根据客户端来源,语言,文字,判定应该显示那一种网页,多用于跨国服务器等;AllowOverride
:表示是否允许下面的控制法则生效; AllowOverride
支持以下的几种选项: FileInfo
:AuthConfig
:基于文件里面的帐号和密码来进行访问,这个密码文件需要额外的进行指定,基于用户或者是组来尽心访问Limit
:Order allow,deny
:用于定义服务器的访问控制顺序,deny
是默认值;Allow from all
:用于定义服务器的访问控制方式;IP
network/netmask
HOSTNAME
DOMAINNAME
Partual IP:172.16,172.16.0.0/16
,缺省的IP
地址;
AllowOverride AuthConfig
AuthType Basic
AuthName "Restricted Site....."
AuthUserFile "/etc/httpd/conf/ht.passwd"
Require valid-user
[root@server3 ~]# htpasswd -c -m /etc/httpd/conf/ht.passwd hadoop
New password:
Re-type new password:
Adding password for user hadoop
[root@server3 ~]# htpasswd -m /etc/httpd/conf/ht.passwd openstack
New password:
Re-type new password:
Adding password for user openstack
[root@server3 ~]# httpd -t
Syntax OK
[root@server3 ~]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
AllowOverride AuthConfig
AuthType Basic
AuthName "Restricted Site....."
AuthUserFile "/etc/httpd/conf/ht.passwd"
Require user hadoop
[root@server3 ~]# httpd -t
Syntax OK
[root@server3 ~]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@server3 ~]# vim /etc/httpd/conf/httpd.conf
AllowOverride AuthConfig
AuthType Basic
AuthName "Restricted Site....."
AuthUserFile "/etc/httpd/conf/ht.passwd"
AuthGroupFile "/etc/httpd/conf/htgroup"
Require user hadoop
/etc/httpd/conf/htgroup
添加
myusers:hadoop openstack
<IfModule mod_userdir.c>
UserDir disabled
IfModule
httpd -M
用于查看HTTPD
支持的所有模块userdir_module
:表示是否允许用户在自己的家目录里面建立网页发布目录的.如果希望能够进行访问,还需要更改权限;userdir_module
的示例[root@server3 conf]# vim httpd.conf
启用
UserDir public_html
[root@server3 conf]# useradd westos
[root@server3 conf]# id westos
id: hadop: No such user
[root@server3 conf]# passwd westos
Changing password for user westos.
New password:
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@server3 conf]# su - westos
[hadoop@server3 ~]$ ls
[hadoop@server3 ~]$ mkdir public_html
[hadoop@server3 ~]$ cd public_html/
[hadoop@server3 public_html]$ vim
test.westos.usedir
[root@server3 conf]# chmod o+x /home/westos/ -R
[root@server3 conf]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
# UserDir: The name of the directory that is appended onto a user's home
# directory if a ~user request is received.
#
# The path to the end user account 'public_html' directory must be
# accessible to the webserver userid. This usually means that ~userid
# must have permissions of 711, ~userid/public_html must have permissions
# of 755, and documents contained therein must be world-readable.
# Otherwise, the client will only receive a "403 Forbidden" message.
~userid
更改为711
,将~userid/public_html
更改为755
;[root@server3 conf]# chmod 711 /home/westos/
[root@server3 conf]# chmod 755 /home/westos/public_html/
# //用于定义每用户家目录的访问信息
# AllowOverride FileInfo AuthConfig Limit //和上面的定义是一样的
# Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
# //定义对于这些目录的资源获取的方法
# Order allow,deny
# Allow from all
#
# //表示不在权限定义范围内的资源获取方法如何进行处理;
# Order deny,allow
# Deny from all
#
#
DirectoryIndex
:表示默认的主页名称,自左而右进行匹配;AccessFileName .htaccess
:用于控制对于每个目录的访问控制,对于一个目录里面创建这个,然后写访问控制权限;TypesConfig /etc/mime.types
:用于使httpd传输支持哪种文件类型;DefaultType text/plain
:如果不指名文本信息,当作纯文本信息; HostnameLookups Off
:表示用于记录主机名需要将IP地址进行反解,是很浪费时间的;LogFormat
:表示对于日志的记录格式,例如"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined:
%h
:client
地址;%l
:client
主机登录名称;%u
:登录网站使用的用户;%t
:表示时间产生的时间;\"%r\"
:请求报文的第一行;%>s
:最后一次请求的页面的状态码;%b
:响应报文的大小;\"%{Referer}i\"
:表示是从哪一个页面过来的;\"%{User-Agent}i\"
:客户端使用的代理;PV
:Page View
,页面访问量,每天的页面访问量,必须是完整页面的访问量,不是单个资源的访问量;US
:user view
:用户访问量,独立的IP
量;Alias /icons/ "/var/www/icons/"
:表示路径别名,用于将其他路径底下的路径名映射为网页发布目录的路径里面别名;[root@server3 conf]# mkdir -pv /www/bbs
[root@server3 conf]# vim httpd.conf
添加:
Alias /luntan "/www/bbs"
[root@server3 conf]# vim /www/bbs/index.html
[root@server3 conf]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
建议安装
[root@server3 conf]# yum install httpd-manual.noarch -y
[root@server3 conf]# /etc/init.d/httpd restart
Stopping httpd: [FAILED]
Starting httpd: [ OK ]