apache配置文件

apache配置文件(总共不过500行,结构大概这样)

++++

1

ServerRoot "/usr/local/apache"

2

Listen 80

3

能够使用作为DSO构建的模块的功能

LoadModule php7_module        modules/libphp7.so

<IfModule mpm_prefork_module>

#LoadModule cgi_module modules/mod_cgi.so

</IfModule>

4主站点位置

DocumentRoot "/usr/local/apache/htdocs"

<Directory "/usr/local/apache/htdocs">

Options Indexes FollowSymLinks

AllowOverride None

Require all granted

</Directory>

 

5错误日志

ErrorLog "logs/error_log"

LogLevel warn

 

6支持某种文件类型

<IfModule mime_module>

AddType application/x-httpd-php .php

    AddType application/x-compress .Z

    AddType application/x-gzip .gz .tgz

</IfModule>

 

+++++

 

 

 

http://www.cnblogs.com/lyh15/p/7612670.html

ServerRoot "/mnt/software/apache2" #你的apache软件安装的位置。其它指定的目录如果没有指定绝对路径,则目录是相对于该目录。 

PidFile logs/httpd.pid #第一个httpd进程(所有其他进程的父进程)的进程号文件位置。 

Listen 80 #服务器监听的端口号。 

ServerName www.clusting.com:80 #主站点名称(网站的主机名)。 

ServerAdmin admin@clusting.com #管理员的邮件地址。 

DocumentRoot "/mnt/web/clusting" #主站点的网页存储位置

 

 

 

<Directory "/usr/local/apache/htdocs">

Options Indexes FollowSymLinks

AllowOverride None

Require all granted

 </Directory>

 

以下是对主站点的目录进行访问控制:

<Directory "/mnt/web/clusting"> 
Options FollowSymLinks 
AllowOverride None 
Order allow,deny 
Allow from all 
</Directory>

在上面这段目录属性配置中,主要有下面的选项:

Options:配置在特定目录使用哪些特性,常用的值和基本含义如下:

ExecCGI: 在该目录下允许执行CGI脚本。

FollowSymLinks: 在该目录下允许文件系统使用符号连接。

Indexes: 当用户访问该目录时,如果用户找不到DirectoryIndex指定的主页文件(例如index.html),则返回该目录下的文件列表给用户。

SymLinksIfOwnerMatch: 当使用符号连接时,只有当符号连接的文件拥有者与实际文件的拥有者相同时才可以访问。

其它可用值和含义请参阅:http://www.clusting.com/Apache/ApacheManual/mod/core.html#options


AllowOverride:允许存在于.htaccess文件中的指令类型(.htaccess文件名是可以改变的,其文件名由AccessFileName指令决定): 
None: 当AllowOverride被设置为None时。不搜索该目录下的.htaccess文件(可以减小服务器开销)。

All: 在.htaccess文件中可以使用所有的指令。

其他的可用值及含义(如:Options FileInfo AuthConfig Limit等),请参看: http://www.clusting.com/Apache/ApacheManual/mod/core.html#AllowOverride

Order:控制在访问时Allow和Deny两个访问规则哪个优先:

Allow:允许访问的主机列表(可用域名或子网,例如:Allow from 192.168.0.0/16)。

Deny:拒绝访问的主机列表。

更详细的用法可参看:http://www.clusting.com/Apache/ApacheManual/mod/mod_access.html#order

DirectoryIndex index.html index.htm index.php #主页文件的设置(本例将主页文件设置为:index.html,index.htm和index.php

 

别名设置 
对于不在DocumentRoot指定的目录内的页面,既可以使用符号连接,也可以使用别名。别名的设置如下:

Alias /download/ "/var/www/download/" #访问时可以输入:http://www.custing.com/download/

<Directory "/var/www/download"> #对该目录进行访问控制设置 
Options Indexes MultiViews 
AllowOverride AuthConfig 
Order allow,deny 
Allow from all 
</Directory>

 

日志的设置

(1)错误日志的设置 
ErrorLog logs/error_log #日志的保存位置 
LogLevel warn #日志的级别

 

  • 虚拟主机的配置 

 

<VirtualHost *:80>

    ServerAdmin webmaster@dummy-host.example.com

    DocumentRoot "/usr/local/apache/docs/dummy-host.example.com"

    ServerName dummy-host.example.com

    ServerAlias www.dummy-host.example.com

    ErrorLog "logs/dummy-host.example.com-error_log"

    CustomLog "logs/dummy-host.example.com-access_log" common

</VirtualHost>

 

虚拟主机的配置 
(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>

 

 

+++++++

虚拟目录配置

 

<IfModule dir_module>  

    #设置欢迎界面  

    DirectoryIndex index.php index.html index.htm  

    #配置别名,就是浏览器访问时用的。 localhost/ws  

    Alias  /ws "D:/PHP/work"  

    <Directory "D:/PHP/work">  

    #权限,只针对当前的目录而言  

    Order allow,deny  

    #允许所有人访问  

    Allow from all  

    </Directory>  

</IfModule>  

 

 

 

 

 配置虚拟主机

<VirtualHost 127.0.0.1:80>  

    #你的网站目录  

    DocumentRoot "D:/PHP/work"  

    #你网站的域名  

    ServerName www.gaotong2055.com  

    ErrorLog "logs/dummy-host2.example.com-error.log"  

    CustomLog "logs/dummy-host2.example.com-access.log" common  

    #权限设置  

    Order allow,deny  

    Allow from all  

</VirtualHost>  

 

posted @ 2017-12-01 10:46  克维拉  阅读(200)  评论(0编辑  收藏  举报