1. 程式人生 > >Apache配置本地web服務

Apache配置本地web服務

1. 下載並安裝Apache Http Server
下載:我這裡是下載的2.2.25版本的,安裝環境為Windows;
下載連結:http://rj.baidu.com/soft/detail/14824.html?ald
安裝:安裝比較簡單,直接下一步;後面會讓填一些資訊,按照格式填就好了;
2.配置Apache

在安裝目錄下去開啟Apache配置檔案“httpd.conf”:我的安裝目錄為D:\Program Files\Apache Software Foundation\Apache2.2,所以我的配置檔案位置D:\Program Files\Apache Software Foundation\Apache2.2\conf。
具體配置:

  • “下面配置檔案中,#”為註釋標記
  • 為了避免伺服器埠號與其他應用埠號使用產生衝突,找到如下程式碼,將這裡這裡的監聽埠號“Listen 80”修改為“Listen 8080”。如下:
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses. # #Listen 12.34.56.78:80 Listen 80
  • 找到ServerName, 配置伺服器域名,這裡由於我沒有申請相應域名,直接設定為本機回送地址127.0.0.1,埠號同樣設定為8080.如下:
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup. # # If your host doesn't have a registered DNS name, enter its IP address here. # ServerName 127.0.0.1:8080
  • 找到DocumentRoot,配置本地web工程根目錄(即存放需要的網頁的位置),我這裡在D盤下建立了一個名為”www“的資料夾,故而把路徑配置為:DocumentRoot “D:/www”。如下:
#
# 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 "D:/www"
  • 找到如下程式碼段,配置指定路徑下的檔案訪問許可權。先將修改為與上面路徑相同,即
#
# 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 "D:www/">
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Allow from all
    Satisfy all 
</Directory>
  • 設定預設開啟的網頁,即主頁。找到DirectoryIndex程式碼段。在後面新增預設開啟的檔名(包括字尾),優先順序從左到右遞減。
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html index.htm
</IfModule>

基本配置到此結束,接下來可以測試一下配置結果。
3. 測試配置結果
  • 將自己寫的網頁放到D:/www路徑下;