尝试学习如何在Apache2.4上设置虚拟主机。
我有2个或更多虚拟主机,“ vhost1”,“ vhost2”,依此类推。这些虚拟主机的DocumentRoot中有一个“ index.html”,其{DocumentRoot} / cgi-bin目录中有一个“ step2.cgi”。
目标是从DocumentRoot中的index.html中,我要单击该index.html中包含的链接,以转到虚拟主机的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文件中的错误是:
[Sun Oct 20 00:33:37.611844 2019] [cgi:error] [pid 3770] [客户端 192.168.0.103:63367] AH02811:找不到脚本或无法统计该脚本:/srv/www/cgi-bin/step2.cgi,引荐网址:http://vhost1.local/
答案 0 :(得分:0)
找到了!
似乎在“”指令之前需要“ scriptalias”指令。
赞:
ScriptAlias /cgi-bin/ "/srv/www/vhosts/vhost1/cgi-bin/"
<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>