我正在尝试在 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 [email protected]
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>
将“拒绝所有人”改为“允许所有人”。现在它起作用了,我再次感谢你,但是,我是否刚刚犯了重大的安全错误?
答案1
禁止
您无权访问此服务器上的/。
查看 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>
,更改ServerName
为public.example.com
,在<VirtualHost *:8080>
,更改ServerName
为private.example.com
。
重新启动 Apache,并浏览到http://public.example.com
和http://private.example.com:8080
以查看发生了什么。