在Apache下开启SSI配置支持include shtml html和快速配置服务器

作为前端开发,使用Apache快速搭建服务器极为方便。

1.找到apach安装目录,找到conf目录下 的httpd.conf

使用SSI(Server Side Include)的html文件扩展名,SSI(Server Side Include),通常称为"服务器端嵌入"或者叫"服务器端包含",是一种类似于ASP的基于服务器的网页制作技术。默认扩展名是 .stm、.shtm 和 .shtml。

  # AddType text/html .shtml

  # AddOutputFilter INCLUDES .shtml

  把这两行前面的#去掉 添加 .html类型之后碎片引入支持.html文件了。
   AddType text/html .shtml .html
  AddOutputFilter INCLUDES .shtml .html
  然后搜索“Options Indexes FollowSymLinks”   在搜索到的那一行后面添加“ Includes”   即将该行改变为 Options Indexes FollowSymLinks Includes   熟悉apache manual的可能会觉得比较容易。   保存httpd.conf,重起apache即可

include元素能按file属性或virtual属性判断应该包含的文件。

file属性是一个相对于当前目录的文件路径,即不能是一个绝对路径(以"/"开头)或包含"../"的路径。

virtual属性可能更有用,它是一个相对于被提供的文档的URL ,可以以"/"开头,但必须与被提供的文档位于同一服务器上。

<!--#include virtual="/header.html" -->

2.快速配置服务器 找到conf目录下 的httpd.conf

把下面配置放在配置文件顶部即可快速搭建一个8200端口的服务器。复制该模块,修改端口和文件目录路径,即可快速搭建另外一个服务器。

 

#rho

Listen 8200

<VirtualHost *:8200>  

    documentroot  "E:\work\rho"

    servername  localhost:8200

    <Directory "E:\work\rho">

    Options Indexes FollowSymLinks Includes

    #ErrorDocument 404 /index.shtml

    AllowOverride All

    Allow from all

    </Directory>

</VirtualHost>

 

配置文件默认配置:80端口,把端口和文件目录换成不常用的目录或端口,就可以直接吧上面快速配置服务器的配置改成80端口使用。下面的配置几乎跟上面等价。

#Listen 12.34.56.78:80
Listen 80

 

ServerName localhost:80

#

# 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 "e:/work/xtl" 

#

# Each directory to which Apache has access can be configured with respect

# to which services and features are allowed and/or disabled in that

# directory (and its subdirectories). 

#

# First, we configure the "default" to be a very restrictive set of 

# features.  

#

<Directory />

    Options FollowSymLinks

    AllowOverride None

    Order deny,allow

    Deny from all

</Directory>

#

# Note that from this point forward you must specifically allow

# particular features to be enabled - so if something's not working as

# you might expect, make sure that you have specifically enabled it

# below.

#

#

# This should be changed to whatever you set DocumentRoot to.

#

<Directory "e:/work/xtl">

    #

    # Possible values for the Options directive are "None", "All",

    # or any combination of:

    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

    #

    # Note that "MultiViews" must be named *explicitly* --- "Options All"

    # doesn't give it to you.

    #

    # The Options directive is both complicated and important.  Please see

    # http://httpd.apache.org/docs/2.2/mod/core.html#options

    # for more information.

    #

    Options Indexes FollowSymLinks Includes

    # AllowOverride controls what directives may be placed in .htaccess files.

    # It can be "All", "None", or any combination of the keywords:

    #   Options FileInfo AuthConfig Limit

    #

    AllowOverride all

    #

    # Controls who can get stuff from this server.

    #

#   onlineoffline tag - don't remove

    Order Deny,Allow

    allow from all

    Allow from 127.0.0.1

</Directory>

 

 

3.配置允许通过IP访问服务器

 

默认的 http.conf 一段和访问控制有关的代码如下:

 


#   onlineoffline tag - don't remove
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1

 

 

 

在httpd.conf文件中,修改如下  

 

Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all

注意要Allow from all,这样才允许所有的IP访问。如果只是允许如下两个网段访问则:
Allow from 172.16.86.0/255.255.255.0 10.0.0.0/255.0.0.0
IP之间不是","逗号,而是空格

 

你可能感兴趣的:(include)