跳轉到內容

XForms/Apache

來自華夏公益教科書,開放的書籍,開放的世界

Apache 網路伺服器是網際網路上最受歡迎的網路伺服器。它提供高效能的網頁服務,非常安全。

預設情況下,開箱即用的 Apache 伺服器不允許使用者將檔案寫入網路伺服器。這是出於安全原因。

警告:以下內容僅應在內聯網伺服器上使用,並應由您組織的安全專業人員進行審查。

配置 Apache HTTP 伺服器以啟用“PUT”操作的步驟

[編輯 | 編輯原始碼]
  1. 從 apache.org 下載並安裝 HTTP 伺服器。我使用的是 v2.2.4
  2. 驗證它是否按預期提供常規的 xhtml 檔案
  3. 停止服務
  4. 在您的 httpd.conf 中,取消對 dav_module 和 dav_fs_module 的 LoadModule 的註釋,還取消對“Include conf/extra/httpd-dav.conf”行的註釋,以便載入 httpd-dav.conf
  5. 編輯 conf/extras/httpd-dav.conf 並更改“uploads”別名和目錄,使其符合您的要求。當然,它們應該匹配。
  6. 要對使用者進行身份驗證,您可以使用 htpasswd 命令列程式來建立密碼並將其放在 uploads 目錄中。當然,您也可以在專案的測試階段停用密碼保護。

示例 httpd-dav.conf 檔案

[編輯 | 編輯原始碼]

這是我的 httpd-dav.conf 完成後的開頭部分

   DavLockDB "E:/httpd/Apache2.2/var/DavLock"
   Alias /uploads "C:/www/xforms/uploads"

   <Directory "C:/www/xforms/uploads">
   Dav On

   Order Allow,Deny
   Allow from all

#AuthType Digest

   AuthType Basic
   AuthName DAV-upload

# You can use the htdigest program to create the password database:
# htdigest -c "E:/httpd/Apache2.2/user.passwd" DAV-upload admin
# AR: I used htpasswd -> htpasswd -c "C:/www/xforms/uploads/user.passwd" admin
#AuthUserFile "E:/httpd/Apache2.2/user.passwd"
   AuthUserFile "C:/www/xforms/uploads/user.passwd"

# Allow universal read-access, but writes are restricted
# to the admin user.
   <LimitExcept GET OPTIONS>
      require user admin
   </LimitExcept>
   </Directory>

重新啟動 Apache

[編輯 | 編輯原始碼]

對 Apache 配置檔案進行任何更改後,您必須使用 Apache 重新啟動命令重新啟動 Apache,例如

  apachectl restart

 apachectl stop
 apachectl start

如果遇到問題,請確保檢查 Apache 日誌檔案。如果您遇到錯誤,您可能沒有為表單寫入的資料夾設定正確的許可權。

檢查訪問日誌檔案

[編輯 | 編輯原始碼]

如果您的表單未儲存,您還可以檢查 Apache 訪問日誌檔案。它們通常位於以下目錄中:

  Windows: C:\Program Files\Apache Software Foundation\Apache2.2\logs\access.log

如果您看到類似以下內容的行:

192.168.1.105 - - [08/Feb/2007:16:58:01 -0600] "PUT /forms/data.xml HTTP/1.1" 405 235

這表明您收到的是 **HTTP 405 錯誤**:方法不允許。當客戶端嘗試使用伺服器不允許的“請求方法”(如 PUT 或 POST)時,會返回 405 狀態程式碼。這意味著您的配置尚不正確,並且您的 XForms 不會儲存其資料。

參考資料

[編輯 | 編輯原始碼]

此示例由來自 IBM Corporation Austin TX 的 Aaron Reed 建議。


華夏公益教科書