我正在使用 cgi 技术制作一个简单的网站。我创建了一个名为“www.myexamp.com”的域名。我已经为我的网站提供了配置。
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerName www.myexamp.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/myexamp
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted
</Directory>
</VirtualHost>
好的。我可以使用我的域名“www.myexamp.com”访问 cgi 文件。例如,当我输入 URL 为“www.myexamp.com/cgi-bin/hello.cgi”时。它给出了正确的结果。但是当我尝试打开某个 pdf 文件(“www.myexamp.com/cgi-bin/test.pdf”)时,它给出了如下结果:
500 内部服务器错误 内部服务器错误
服务器遇到内部错误或配置错误,无法完成您的请求。
请联系服务器管理员 webmaster@localhost,告知他们此错误发生的时间,以及您在出现此错误之前执行的操作。
有关此错误的更多信息可能在服务器错误日志中提供。Apache/2.4.7 (Ubuntu) 服务器位于 www.myexamp.com 端口 80
我应该配置我的站点配置文件来读取 pdf 文件吗?
答案1
ScriptAlias 指令具有与 Alias 指令相同的行为,不同之处在于它还将目标目录标记为包含将由 mod_cgi 的 cgi 脚本处理程序处理的 CGI 脚本。
以及mod_cgi 手册:
任何具有处理程序 cgi-script 的文件都将被视为 CGI 脚本,并由服务器运行,其输出将返回到客户端。文件通过具有包含 AddHandler 指令定义的扩展名的名称或位于 ScriptAlias 目录中来获取此处理程序。
因此,您应该更改文件的路径test.pdf
,例如,尝试在路径中更改mv
它:DocumentRoot
mv /usr/lib/cgi-bin/test.pdf /var/www/myexamp/test.pdf