【发布时间】:2020-02-16 14:15:15
【问题描述】:
正在尝试学习如何在 Apache2.4 上设置虚拟主机。
我有 2 个或更多虚拟主机,“vhost1”、“vhost2”等。这些虚拟主机在其 DocumentRoot 中有一个“index.html”,在其 {DocumentRoot}/cgi-bin 目录中有一个“step2.cgi”。
我的目标是从 DocumentRoot 中的 index.html 中单击该 index.html 中包含的链接以转到 vhost 的 cgi-bin 目录并从那里运行脚本。
我看到的问题是,如果我单击 index.html 中的链接,该链接会尝试在默认服务器的 DocumentRoot 中打开指定的文件。并且,得到一个“错误 404”作为响应。
我如何获得一个相对 URL 链接来激活我开始使用的虚拟主机的 cgi-bin 目录中的 cgi?
我注意到,如果我在 index.html 中有一个仅引用“step1.html”的链接,则该页面会正确显示。
我做错了什么?谢谢!
我有一个配置如下的虚拟主机:
<VirtualHost *>
DocumentRoot /srv/www/vhosts/vhost1/htdocs
ServerName vhost1.local
ServerAlias vhost1
ServerAdmin root@server1.local
<Directory /srv/www/vhosts/vhost1/htdocs/>
DirectoryIndex index.cgi
DirectoryIndex index.html
AddHandler cgi-script .cgi
AddHandler cgi-script .pl
AllowOverride None
Options +ExecCGI -Includes
Require all granted
</Directory>
<Directory /srv/www/vhosts/vhost1/cgi-bin/>
DirectoryIndex index.cgi
AddHandler cgi-script .cgi
AddHandler cgi-script .pl
AllowOverride None
Options +ExecCGI -Includes
Require all granted
</Directory>
CustomLog /srv/www/vhosts/vhost1/logs/access_log vhost_common
ErrorLog /srv/www/vhosts/vhost1/logs/error_log
</VirtualHost>
index.html 看起来像:
<html>
<head>
<title>
My page title
</title>
</head>
<body>
<a href="http://vhost1.local/cgi-bin/step2.cgi">
Click here:
</a>
<a href="step1.html">
or here:
</a>
</body>
</html>
而error_log文件中的错误是:
[2019 年 10 月 20 日星期日 00:33:37.611844] [cgi:error] [pid 3770] [client 192.168.0.103:63367] AH02811:找不到脚本或无法统计:/srv/www/cgi-bin/step2.cgi,引用者:http://vhost1.local/
【问题讨论】:
标签: apache2 virtualhost