Ubuntu

設置一個基本的 mod_proxy 虛擬主機

  • October 26, 2012

我正在嘗試設置一個基本的虛擬主機,將所有對 test.local 的請求代理到我在 127.0.0.1:8080 上執行的 WEBrick 伺服器,同時保持對 localhost 的所有請求都轉到我在 /var/www 中的靜態文件。我正在執行 Ubuntu 10.04。

我安裝了 libapache2-mod-proxy-html 並且我使用 a2enmod 代理啟用了該模組。我還啟用了我的虛擬主機。但是,每當我去 test.local 時,我總是會收到一個神秘的 500 伺服器錯誤,並且我的所有日​​誌都告訴我:

[Thu Mar 03 01:43:10 2011] [warn] proxy: No protocol handler was valid for the URL /. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.

這是我的虛擬主機:

<VirtualHost test.local:80>
   LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
   ServerAdmin webmaster@localhost
   ServerName test.local
   ProxyPreserveHost On

   # prevents this folder from being proxied
   ProxyPass /static !

   DocumentRoot /var/www
   <Directory />
       Options FollowSymLinks
       AllowOverride None
   </Directory>
   <Directory /var/www/>
       Options Indexes FollowSymLinks MultiViews
       AllowOverride None
       Order allow,deny
       allow from all
   </Directory>

   <Proxy *>
       Order allow,deny
       Allow from all
   </Proxy>
   ProxyPass / http://localhost:8080/
   ProxyPassReverse / http://localhost:8080/

   ErrorLog /var/log/apache2/error.log

   # Possible values include: debug, info, notice, warn, error, crit,
   # alert, emerg.
   LogLevel warn

   CustomLog /var/log/apache2/access.log combined

這是我對 mod_proxy 的設置:

<IfModule mod_proxy.c>
       #turning ProxyRequests on and allowing proxying from all may allow
       #spammers to use your proxy to send email.

       ProxyRequests Off

       <Proxy *>
       # default settings
               #AddDefaultCharset off
               #Order deny,allow
               #Deny from all
               ##Allow from .example.com

       AddDefaultCharset off
       Order allow,deny
       Allow from all
       </Proxy>

       # Enable/disable the handling of HTTP/1.1 "Via:" headers.
       # ("Full" adds the server version; "Block" removes all outgoing Via: headers)
       # Set to one of: Off | On | Full | Block

       ProxyVia On
</IfModule>

有人知道我做錯了什麼嗎?謝謝

看起來您沒有載入mod_proxy_http模組(代理到 HTTP 伺服器所需的模組)。我面前沒有 Ubuntu 10.04,但 IIRC 是這樣的:

sudo a2enmod proxy_http

上述答案對我沒有幫助,因為我收到的錯誤與作者在所選答案中的評論相同。但是,我確實找到了以下文章並進行了更改,從而解決了我的問題:

sudo /usr/sbin/setsebool -P httpd_can_network_connect 1

來源:http ://allscm.com/archives/apache2-proxy-disabled-connection-on-localhost.html

引用自:https://serverfault.com/questions/242650