Virtualhost

Slackware 上的 Apache2:VirtualHost 配置 - 埠 8080 上的連接被拒絕

  • December 8, 2013

我正在嘗試在 Slackware 伺服器上配置虛擬主機並且遇到了故障。

當我瀏覽到 localhost 或 127.0.0.1 時,我得到:

Forbidden

You don't have permission to access / on this server.

我需要在 8080 完成 WebApp 的配置。當我瀏覽到 localhost:8080 或 127.0.0.1:8080 時,我得到:

Unable to connect

         Firefox can't establish a connection to the server at 127.0.0.1:8080.

一些上下文:我需要在 Slackware 上為 Debian/Ubuntu 複製以下說明並且需要幫助 — 所以這裡是 Debian 版本:

5. sudo ln -s /etc/koha/koha-httpd.conf /etc/apache2/sites-available/koha
6. sudo a2enmod rewrite deflate
7. sudo a2ensite koha && /etc/init.d/apache2 reload

到目前為止:我的 httpd.conf(LoadModule 的東西和評論被遺漏了)

ServerRoot "/usr"
Listen 127.0.0.1:80
User apache
Group apache
ServerAdmin you@example.com
ServerName localhost:80
DocumentRoot "/srv/httpd/htdocs"
<Directory />
   Options FollowSymLinks
   AllowOverride None
   Order deny,allow
   Deny from all
</Directory>
<Directory "/srv/httpd/htdocs">
   Options Indexes FollowSymLinks
   AllowOverride None
Order allow,deny
   Allow from all
</Directory>
<IfModule dir_module>
   DirectoryIndex index.html
</IfModule>
<Directory "/srv/httpd/cgi-bin">
   AllowOverride None
   Options None
   Order allow,deny
   Allow from all
</Directory>
DefaultType text/plain

Include /etc/httpd/extra/httpd-vhosts.conf
Include /etc/httpd/extra/httpd-default.conf

這是我應該提到的 CGI 應用程序。我將應用程序 apache 配置添加到 /etc/httpd/extra/httpd-vhosts.conf (此處刪除了評論):

NameVirtualHost *:80
<VirtualHost *:80>
  ServerAdmin  webmaster@auction
  DocumentRoot /usr/share/koha/opac/htdocs
  ServerName localhost
  ScriptAlias /cgi-bin/koha/ "/usr/share/koha/opac/cgi-bin/opac/"
  ScriptAlias /index.html "/usr/share/koha/opac/cgi-bin/opac/opac-main.pl"
  ScriptAlias /opac-search.pl "/usr/share/koha/opac/cgi-bin/opac/opac-search.pl"
  ScriptAlias /search "/usr/share/koha/opac/cgi-bin/opac/opac-search.pl"
  ErrorLog /var/log/koha/koha-opac-error_log
  SetEnv KOHA_CONF "/etc/koha/koha-conf.xml"
  SetEnv PERL5LIB "/usr/share/koha/lib"
  <IfModule mod_gzip.c>
    mod_gzip_on yes
    mod_gzip_dechunk yes
    mod_gzip_keep_workfiles No
    mod_gzip_can_negotiate yes
    mod_gzip_update_static No
    mod_gzip_temp_dir /tmp
    mod_gzip_minimum_file_size 512
    mod_gzip_maximum_file_size 1000000
    mod_gzip_maximum_inmem_size 1000000
    mod_gzip_handle_methods GET POST
    mod_gzip_item_exclude reqheader "User-Agent: .*Mozilla/4\..*\["
    mod_gzip_item_exclude mime ^image/.*
    mod_gzip_item_exclude rspheader Content-Type:image/*
    mod_gzip_item_include file \.js$
    mod_gzip_item_include mime ^application/javascript$
    mod_gzip_item_include mime ^application/x-javascript$
    mod_gzip_item_include file \.php$
    mod_gzip_item_include mime ^text/html$
    mod_gzip_item_include file \.css$
    mod_gzip_item_include mime ^text/css$
 </IfModule>
 <IfModule mod_deflate.c>
   # Compress content with type html, text, and css, ...
   AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css
   AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript
   DeflateCompressionLevel 9
   # Properly handle old browsers that do not support compression
   BrowserMatch ^Mozilla/4 gzip-only-text/html
   BrowserMatch ^Mozilla/4\.0[678] no-gzip
   BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
   DeflateFilterNote Input instream
   DeflateFilterNote Output outstream
   DeflateFilterNote Ratio ratio
   LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
   <IfModule mod_headers.c>
      #properly handle requests coming from behind proxies
      Header append Vary User-Agent
   </IfModule>
 </IfModule>
  Options +FollowSymLinks
  ErrorDocument 400 /cgi-bin/koha/errors/400.pl
  ErrorDocument 401 /cgi-bin/koha/errors/401.pl
  ErrorDocument 403 /cgi-bin/koha/errors/403.pl
  ErrorDocument 404 /cgi-bin/koha/errors/404.pl
  ErrorDocument 500 /cgi-bin/koha/errors/500.pl
  RewriteEngine On
  RewriteCond %{QUERY_STRING} (.*?)(?:[A-Za-z0-9_-]+)=&(.*)
  RewriteRule (.+) $1?%1%2 [N,R,NE]
  RewriteRule ^/bib/([^\/]*)/?$ /cgi-bin/koha/opac-detail\.pl?bib=$1 [PT]
  RewriteRule ^/isbn/([^\/]*)/?$ /search?q=isbn:$1 [PT]
  RewriteRule ^/issn/([^\/]*)/?$ /search?q=issn:$1 [PT]
</VirtualHost>
<VirtualHost *:8080>
  ServerAdmin webmaster@auction
  DocumentRoot /usr/share/koha/intranet/htdocs
  ServerName localhost:8080
  ScriptAlias /cgi-bin/koha/ "/usr/share/koha/intranet/cgi-bin/"
  ScriptAlias /index.html "/usr/share/koha/intranet/cgi-bin/mainpage.pl"
  ScriptAlias /search "/usr/share/koha/intranet/cgi-bin/search.pl"
  ErrorLog /var/log/koha/koha-error_log
  SetEnv KOHA_CONF "/etc/koha/koha-conf.xml"
  SetEnv PERL5LIB "/usr/share/koha/lib"
  Options +FollowSymLinks
  ErrorDocument 400 /cgi-bin/koha/errors/400.pl
  ErrorDocument 401 /cgi-bin/koha/errors/401.pl
  ErrorDocument 403 /cgi-bin/koha/errors/403.pl
  ErrorDocument 404 /cgi-bin/koha/errors/404.pl
  ErrorDocument 500 /cgi-bin/koha/errors/500.pl
  <IfModule mod_gzip.c>
    mod_gzip_on yes
    mod_gzip_dechunk yes
    mod_gzip_keep_workfiles No
    mod_gzip_can_negotiate yes
    mod_gzip_update_static No
    mod_gzip_temp_dir /tmp
    mod_gzip_minimum_file_size 512
    mod_gzip_maximum_file_size 1000000
    mod_gzip_maximum_inmem_size 1000000
    mod_gzip_handle_methods GET POST
    mod_gzip_item_exclude reqheader "User-Agent: .*Mozilla/4\..*\["
    mod_gzip_item_exclude mime ^image/.*
    mod_gzip_item_exclude rspheader Content-Type:image/*
    mod_gzip_item_include file \.js$
    mod_gzip_item_include mime ^application/javascript$
    mod_gzip_item_include mime ^application/x-javascript$
    mod_gzip_item_include file \.php$
    mod_gzip_item_include mime ^text/html$
    mod_gzip_item_include file \.css$
    mod_gzip_item_include mime ^text/css$
  </IfModule>
  <IfModule mod_deflate.c>
    # Compress content with type html, text, and css, ...
    AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css
    AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript
    DeflateCompressionLevel 9
    # Properly handle old browsers that do not support compression
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    DeflateFilterNote Input instream
    DeflateFilterNote Output outstream
    DeflateFilterNote Ratio ratio
    LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
    <IfModule mod_headers.c>
      #properly handle requests coming from behind proxies
      Header append Vary User-Agent
    </IfModule>
 </IfModule>
  RewriteEngine On    
  RewriteCond %{QUERY_STRING} (.*?)(?:[A-Za-z0-9_-]+)=&(.*)
  RewriteRule (.+) $1?%1%2 [N,R,NE]
  RewriteRule ^/bib/([^\/]*)/?$ /cgi-bin/koha/detail\.pl?bib=$1 [PT]
  RewriteRule ^/isbn/([^\/]*)/?$ /search?q=isbn:$1 [PT]
  RewriteRule ^/issn/([^\/]*)/?$ /search?q=issn:$1 [PT]
</VirtualHost>

我在這裡錯過了一個基本的基礎嗎?我應該提到模組 deflate、rewrite 和 perl 已安裝並在 LoadModule 指令中。

謝謝!

布布諾夫

更新 - 有一個關注/問題

首先——感謝 quanta 迄今為止的幫助。我懷疑存在權限問題,並將其添加到我的 httpd.conf 目錄節中。

<Directory "/srv/httpd/cgi-bin">
   AllowOverride None
   Options None
   Order allow,deny
   Allow from all
</Directory>

將全部拒絕更改為“全部允許”。所以現在它起作用了,我再次感謝你,但是,我剛剛犯了重大的安全錯誤嗎?

禁止的

您無權訪問此伺服器上的 /。

看看 Apache 錯誤日誌,它會告訴你更多細節。

兩個都。公共端為 80,管理/內聯網端為 8080。

出於測試目的,將 2 個主機名添加到/etc/hosts

127.0.0.1 public.example.com
127.0.0.1 private.example.com

更改Listen從:

Listen 127.0.0.1:80

Listen 80
Listen 8080

重新啟動 Apache 並確保 Apache 正在監聽兩個埠:

netstat -nlp | grep httpd

刪除線NameVirtualHost *:80

<VirtualHost *:80>,更改ServerNamepublic.example.com和在<VirtualHost *:8080>,更改ServerNameprivate.example.com

重新啟動 Apache,然後瀏覽http://public.example.comhttp://private.example.com:8080查看會發生什麼。

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