加入收藏 | 设为首页 | 会员中心 | 我要投稿 十堰站长网 (https://www.0719zz.com/)- 混合云存储、网络、视频终端、云计算、媒体处理!
当前位置: 首页 > 运营中心 > Apache > 正文

Apache 配置详解

发布时间:2023-02-20 10:16:33 所属栏目:Apache 来源:互联网
导读:Apache的配置 Apache的配置由httpd.conf文件配置,因此下面的配置指令都是在httpd.conf文件中修改。 主站点的配置(基本配置) (1) 基本配置: ServerRoot /mnt/software/apache2 #你的apache软件安装的位置。其它指定的目录如果没有指定绝对路径,则目录是相对

 
  (2)访问日志设置
 
  日志的缺省格式有如下几种:
  LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined
  LogFormat "%h %l %u %t "%r" %>s %b" common #common为日志格式名称
  LogFormat "%{Referer}i -> %U" referer
  LogFormat "%{User-agent}i" agent
  CustomLog logs/access_log common
 
 
  格式中的各个参数如下:
 
  %h --客户端的ip地址或主机名
  %l --The 这是由客户端 identd 判断的RFC 1413身份,输出中的符号 "-" 表示此处信息无效。
  %u --由HTTP认证系统得到的访问该网页的客户名。有认证时才有效,输出中的符号 "-" 表示此处信息无效。
  %t --服务器完成对请求的处理时的时间。
  "%r" --引号中是客户发出的包含了许多有用信息的请求内容。
  %>s --这个是服务器返回给客户端的状态码。
  %b --最后这项是返回给客户端的不包括响应头的字节数。
  "%{Referer}i" --此项指明了该请求是从被哪个网页提交过来的。
  "%{User-Agent}i" --此项是客户浏览器提供的浏览器识别信息。
 
  下面是一段访问日志的实例:
  192.168.10.22 - bearzhang [10/Oct/2005:16:53:06 +0800] "GET /download/ HTTP/1.1" 200 1228
  192.168.10.22 - - [10/Oct/2005:16:53:06 +0800] "GET /icons/blank.gif HTTP/1.1" 304 -
  192.168.10.22 - - [10/Oct/2005:16:53:06 +0800] "GET /icons/back.gif HTTP/1.1" 304 -
 
  各参数的详细解释,请参阅:http://www.clusting.com/Apache/ApacheManual/logs.html
 
 
  用户认证的配置
  (1)in the httpd.conf:
  AccessFileName .htaccess
  .........
  Alias /download/ "/var/www/download/"
  <Directory "/var/www/download">
  Options Indexes
  AllowOverride AuthConfig
  </Directory>
  (2) create a password file:
  /usr/local/apache2/bin/htpasswd -c /var/httpuser/passwords bearzhang
 
  (3)onfigure the server to request a password and tell the server which users are allowed access.
  vi /var/www/download/.htaccess:
  AuthType Basic
  AuthName "Restricted Files"
  AuthUserFile /var/httpuser/passwords
  Require user bearzhang
  #Require valid-user #all valid user
 
  虚拟主机的配置
  (1)基于IP地址的虚拟主机配置
  Listen 80
  <VirtualHost 172.20.30.40>
  DocumentRoot /www/example1
  ServerName www.example1.com
  </VirtualHost>
  <VirtualHost 172.20.30.50>
  DocumentRoot /www/example2
  ServerName www.example2.org
  </VirtualHost>
 
 
  (2) 基于IP和多端口的虚拟主机配置
  Listen 172.20.30.40:80
  Listen 172.20.30.40:8080
  Listen 172.20.30.50:80
  Listen 172.20.30.50:8080
 
  <VirtualHost 172.20.30.40:80>
  DocumentRoot /www/example1-80
  ServerName www.example1.com
  </VirtualHost>
 
  <VirtualHost 172.20.30.40:8080>
  DocumentRoot /www/example1-8080
  ServerName www.example1.com
  </VirtualHost>
 
  <VirtualHost 172.20.30.50:80>
  DocumentRoot /www/example2-80
  ServerName www.example1.org
  </VirtualHost>
 
  <VirtualHost 172.20.30.50:8080>
  DocumentRoot /www/example2-8080
  ServerName www.example2.org
  </VirtualHost>
 
  (3)单个IP地址的服务器上基于域名的虚拟主机配置:
  # Ensure that Apache listens on port 80
  Listen 80
 
  # Listen for virtual host requests on all IP addresses
  NameVirtualHost *:80
 
  <VirtualHost *:80>
  DocumentRoot /www/example1
  ServerName www.example1.com
  ServerAlias example1.com. *.example1.com
  # Other directives here
  </VirtualHost>
 
  <VirtualHost *:80>
  DocumentRoot /www/example2
  ServerName www.example2.org
  # Other directives here
  </VirtualHost>
 
  (4)在多个IP地址的服务器上配置基于域名的虚拟主机:
  Listen 80
 
  # This is the "main" server running on 172.20.30.40
  ServerName server.domain.com
  DocumentRoot /www/mainserver
 
  # This is the other address
  NameVirtualHost 172.20.30.50
 
  <VirtualHost 172.20.30.50>
  DocumentRoot /www/example1
  ServerName www.example1.com
  # Other directives here ...
  </VirtualHost>
 
  <VirtualHost 172.20.30.50>
  DocumentRoot /www/example2
  ServerName www.example2.org
  # Other directives here ...
  </VirtualHost>
 
  (5)在不同的端口上运行不同的站点(基于多端口的服务器上配置基于域名的虚拟主机):
  Listen 80
  Listen 8080
 
  NameVirtualHost 172.20.30.40:80
  NameVirtualHost 172.20.30.40:8080
 
  <VirtualHost 172.20.30.40:80>
  ServerName www.example1.com
  DocumentRoot /www/domain-80
  </VirtualHost>
 
  <VirtualHost 172.20.30.40:8080>
  ServerName www.example1.com
  DocumentRoot /www/domain-8080
  </VirtualHost>
 
  <VirtualHost 172.20.30.40:80>
  ServerName www.example2.org
  DocumentRoot /www/otherdomain-80
  </VirtualHost>
 
  <VirtualHost 172.20.30.40:8080>
  ServerName www.example2.org
  DocumentRoot /www/otherdomain-8080
  </VirtualHost>
 
  (6)基于域名和基于IP的混合虚拟主机的配置:
  Listen 80
 
  NameVirtualHost 172.20.30.40
 
  <VirtualHost 172.20.30.40>
  DocumentRoot /www/example1
  ServerName www.example1.com
  </VirtualHost>
 
  <VirtualHost 172.20.30.40>
  DocumentRoot /www/example2
  ServerName www.example2.org
  </VirtualHost>
 
  <VirtualHost 172.20.30.40>
  DocumentRoot /www/example3
  ServerName www.example3.net
  </VirtualHost>
 
  SSL加密的配置
 
  首先在配置之前先来了解一些基本概念:
 
  证书的概念:首先要有一个根证书,然后用根证书来签发服务器证书和客户证书,一般理解:服务器证书和客户证书是平级关系。SSL必须安装服务器证书来认证。 因此:在此环境中,至少必须有三个证书:根证书,服务器证书,客户端证书。 在生成证书之前,一般会有一个私钥,同时用私钥生成证书请求,再利用证书服务器的根证来签发证书。
 
  SSL所使用的证书可以自己生成,也可以通过一个商业性CA(如Verisign 或 Thawte)签署证书。
 
  签发证书的问题:如果使用的是商业证书,具体的签署方法请查看相关销售商的说明;如果是知己签发的证书,可以使用openssl自带的CA.sh脚本工具。
 
  如果不为单独的客户端签发证书,客户端证书可以不用生成,客户端与服务器端使用相同的证书。
 
  Listen 443
  SSLPassPhraseDialog buildin
  #SSLPassPhraseDialog exec:/path/to/program
  SSLSessionCache dbm:/usr/local/apache2/logs/ssl_scache
  SSLSessionCacheTimeout 300
  SSLMutex file:/usr/local/apache2/logs/ssl_mutex
 
  <VirtualHost _default_:443>
 
  # General setup for the virtual host
  DocumentRoot "/usr/local/apache2/htdocs"

(编辑:十堰站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读