手机版
你好,游客 登录 注册
背景:
阅读新闻

Web服务(二)httpd配置参数详细介绍

[日期:2014-03-27] 来源:Linux社区  作者:chenpipi [字体:大 中 小]

8、配置日志功能

/var/log/httpd/access.log && error.log

access.log:其需要记录的内容需要自定义

访问日志:

CustomLog "/path/to/access_log_file" Format_Name
LogFormat Format_String Format_Nam

# The following directives define some format nicknames for use with

# a CustomLog directive (see below).

#

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

LogFormat "%h %l %u %t \"%r\" %>s %b" common

LogFormat "%{Referer}i -> %U" referer

LogFormat "%{User-agent}i" agent

#

#

#

%h:客户端地址

%l:远程登录名;通常为-

%u:认证时的远程用户名;通常为-

%t:接受到请求时的时间;

%r:请求报文的起始行;

%>s:响应状态码;

%b:响应报文的长度;单位字节;不包含HTTP首部

%{Header_Name}i:记录指定请求报文首部的内容(value)

%U:请求的URL;不包含其他任何请求串

#

#具体请参照http://httpd.apache.org/docs/2.2/mod/mod_log_config.html

#

# ErrorLog: The location of the error log file.

# If you do not specify an ErrorLog directive within a <VirtualHost>

# container, error messages relating to that virtual host will be

# logged here. If you *do* define an error logfile for a <VirtualHost>

# container, that host's errors will be logged there and not here.

#

ErrorLog logs/error_log

9、路径别名和默认字符集

Alias /alias/ "/path/to/somewhere/" :前面别名结尾有/后面结尾就一定得有/

# We include the /icons/ alias for FancyIndexed directory listings. If you

# do not use FancyIndexing, you may comment this out.

#

Alias /icons/ "/var/www/icons/"

#

#

#字符集

# Specify a default charset for all content served; this enables

# interpretation of all content as UTF-8 by default. To use the

# default browser choice (ISO-8859-1), or to allow the META tags

# in HTML content to override this choice, comment out this

# directive:

#

AddDefaultCharset UTF-8

10、CGI脚本路径别名

URL --> FileSystem Directory

CGI:Common Gateway Interface

有很多机制需要SUID或SGID权限;


httpd无法直接执行脚本;基于CGI协议调用脚本解释器;等待脚本解释器返回结果到web服务器

# ScriptAlias: This controls which directories contain server scripts.

# ScriptAliases are essentially the same as Aliases, except that

# documents in the realname directory are treated as applications and

# run by the server when requested rather than as documents sent to the client.

# The same rules about trailing "/" apply to ScriptAlias directives as to

# Alias.

#

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

ScriptAlias /URL/ "/path/to/somewhere/" #格式;路径需要执行权限

#

#测试

cat << EOF

Content-Type: text/html

<pre>

The hostname is:`hostname`.

The time is:`date`.

</pre>

EOF

11、基于用户的访问控制

虚拟用户:不是系统的账号密码;

在配置文件LoadModule下(auth)开头的认证类型:

basic:基本认证;账号和密钥明文发送;

digest:摘要认证;hash编程之后发送

认证提供者(authentication provider):账号和密钥的存放位置(authn)

授权机制(authentication):根据什么进行授权(authz)

1、编辑配置文件使用:

[Linux]#vi /etc/httpd/conf/httpd.conf

#在<Directory>网站附近下找一个位置新建一个

<Directory "/var/www/html/fin"> #指定目录文件

Options None #没有任何选项

AllowOverride AuthConfig #使用认证配置

AuthType Basic #认证类型

AuthName "Private Area" #质询时窗口标题

# AuthBasicProvider file #认证提供者;默认为文件

AuthUserFile /etc/httpd/conf/.htpasswd #指定文件存放用户账号

# AuthGroupFile /etc/httpd/conf/.htgroup #指定文件存放组

# Require group GroupName #指定组名

Require valid-user #所有的合法账户

</Directory>


2、使用htpasswd命令生成认证库

[Linux]#htpasswd -b /etc/httpd/conf/.htpasswd linuxidc linuxidc

Adding password for user linuxidc

[Linux]#

详细参数可以man htpasswd

SYNOPSIS

htpasswd [ -c ] [ -m ] [ -D ] passwdfile username

htpasswd -b [ -c ] [ -m | -d | -p | -s ] [ -D ] passwdfile username password

htpasswd -n [ -m | -d | -s | -p ] username

htpasswd -nb [ -m | -d | -s | -p ] username password

Web服务(二)httpd配置参数详细介绍 Web服务(二)httpd配置参数详细介绍

12、虚拟主机

一个物理服务器提供多个站点;使用虚拟主机得先取消中心主机

1、基于不同的IP实现不同的虚拟

使用不同IP;


2、基于不同的port实现不同的虚拟主机

使用不同端口

3、基于不同的FQDN实现不同的虚拟主机


使用不同的ServerName的值:FQDN

# DocumentRoot: The directory out of which you will serve your

# documents. By default, all requests are taken from this directory, but

# symbolic links and aliases may be used to point to other locations.

#

#DocumentRoot "/var/www/html" #这项需要先注释;中心主机

#

#基于主机名不同进行测试;下面这项需要开启;IP和port是不需要开启的

NameVirtualHost *:80

#

# NOTE: NameVirtualHost cannot be used without a port specifier

# (e.g. :80) if mod_ssl is being used, due to the nature of the

# SSL protocol.

#

# VirtualHost example:

# Almost any Apache directive may go into a VirtualHost container.

# The first VirtualHost section is used for requests without a known

# server name.

#

<VirtualHost *:80>

ServerAdmin webmaster@linuxidc.com

DocumentRoot /var/www/docs/linuxidc #指定站点路径

ServerName www.linuxidc.com #指定FQDN

ErrorLog logs/linuxidc.com-error_log #指定错误日志路径及名称

CustomLog logs/linuxidc.com-access_log common #指定访问日志路径及名称

</VirtualHost>

<VirtualHost *:80>

ServerAdmin webmaster@88181.com

DocumentRoot /var/www/docs/88181

ServerName www.88181.com

ErrorLog logs/88181.com-error_log

CustomLog logs/88181.com-access_log common

</VirtualHost>

<VirtualHost *:80>

ServerAdmin webmaster@dark.net

DocumentRoot /www/docs/dark

ServerName www.dark.net

ErrorLog logs/dark.net-error_log

CustomLog logs/dark.net-access_log common

</VirtualHost>

#

#配置完成后需要在对应的路径下建立相应的文件

[Linux]#httpd -t

Syntax OK

[Linux]#service httpd restart

Stopping httpd: [ OK ]

Starting httpd: [ OK ]

[Linux]#


配置完成后如在linux下测试则修改/etc/hosts文件;windows下修改C:\Windows\System32\drivers\etc\hosts文件

X.X.X.129 www.linuxidc.com

X.X.X.129 www.88181.com

X.X.X.129 www.dark.net


修改完成后直接访问即可。

#查看日志文件

[Linux]#cd /var/log/httpd/

[Linux]#ls

access_log dark.net-access_log error_log linuxidc.com-access_log 88181.com-access_log

access_log-20140309 dark.net-error_log error_log-20140309 linuxidc.com-error_log 88181.com-error_log

[Linux]# 

httpd的部分参数介绍到这里;下一篇将介绍https的实现httpd-2.4的编译安装。 http://www.linuxidc.com/Linux/2014-03/98761.htm

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款