Apache 配置详解(最好的APACHE配置教程)(3)

(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
</VirtualHost>
<VirtualHost 172.20.30.50>
DocumentRoot /www/example2
ServerName
</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
</VirtualHost>

<VirtualHost 172.20.30.40:8080>
DocumentRoot /www/example1-8080
ServerName
</VirtualHost>

<VirtualHost 172.20.30.50:80>
DocumentRoot /www/example2-80
ServerName
</VirtualHost>

<VirtualHost 172.20.30.50:8080>
DocumentRoot /www/example2-8080
ServerName
</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
ServerAlias example1.com. *.example1.com
# Other directives here
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/example2
ServerName
# 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
# Other directives here ...
</VirtualHost>

<VirtualHost 172.20.30.50>
DocumentRoot /www/example2
ServerName
# 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
DocumentRoot /www/domain-80
</VirtualHost>

<VirtualHost 172.20.30.40:8080>
ServerName
DocumentRoot /www/domain-8080
</VirtualHost>

<VirtualHost 172.20.30.40:80>
ServerName
DocumentRoot /www/otherdomain-80
</VirtualHost>

<VirtualHost 172.20.30.40:8080>
ServerName
DocumentRoot /www/otherdomain-8080
</VirtualHost>

(6)基于域名和基于IP的混合虚拟主机的配置:
Listen 80

NameVirtualHost 172.20.30.40

<VirtualHost 172.20.30.40>
DocumentRoot /www/example1
ServerName
</VirtualHost>

<VirtualHost 172.20.30.40>
DocumentRoot /www/example2
ServerName
</VirtualHost>

<VirtualHost 172.20.30.40>
DocumentRoot /www/example3
ServerName
</VirtualHost>

SSL加密的配置

首先在配置之前先来了解一些基本概念:

证书的概念:首先要有一个根证书,然后用根证书来签发服务器证书和客户证书,一般理解:服务器证书和客户证书是平级关系。SSL必须安装服务器证书来认证。 因此:在此环境中,至少必须有三个证书:根证书,服务器证书,客户端证书。 在生成证书之前,一般会有一个私钥,同时用私钥生成证书请求,再利用证书服务器的根证来签发证书。

SSL所使用的证书可以自己生成,也可以通过一个商业性CA(如Verisign 或 Thawte)签署证书。

签发证书的问题:如果使用的是商业证书,具体的签署方法请查看相关销售商的说明;如果是知己签发的证书,可以使用openssl自带的CA.sh脚本工具。

如果不为单独的客户端签发证书,客户端证书可以不用生成,客户端与服务器端使用相同的证书。
(1) conf/ssl.conf 配置文件中的主要参数配置如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/86316e979ac923e8317162722e3c3e75.html