因此我尝试看看是否可以通过在 Apache 中配置来设置响应标头。
我正在使用 Debian 测试,以防万一。
我的 Web 服务器正常运行,并且我已经将它用于我正在开发的多个网站。所以现在我想要做的就是设置一个标头来查看它是否正常工作。
这是我在 apache.conf 中所做的更改
<Directory /home/web>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Header set myHeader "Hello Header World"
</Directory>
这是我在 /etc/apache2/sites-available/000-default.conf 中的主机配置文件,如下所示:
<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
ServerAdmin webmaster@localhost
DocumentRoot /home/web
AliasMatch ^/vmapi/(.*)$ /home/web/vmapi/api_receiver.php
AliasMatch ^/inherentvalue/api/(.*)$ /home/web/inherentvalue/api/api.php
# 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
Header set location "juancito"
Header set Location "pedrito"
Header set MyHeader "Hello Joe. It took %D microseconds for Apache to serve this request."
# 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
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
这个别名是用于我正在进行的另一个项目的。
apache2ctl -M 的输出也如下所示:
Loaded Modules:
core_module (static)
so_module (static)
watchdog_module (static)
http_module (static)
log_config_module (static)
logio_module (static)
version_module (static)
unixd_module (static)
access_compat_module (shared)
alias_module (shared)
auth_basic_module (shared)
authn_core_module (shared)
authn_file_module (shared)
authz_core_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
deflate_module (shared)
dir_module (shared)
env_module (shared)
filter_module (shared)
headers_module (shared) <-- It's enabled.
mime_module (shared)
mpm_prefork_module (shared)
negotiation_module (shared)
php_module (shared)
reqtimeout_module (shared)
rewrite_module (shared)
setenvif_module (shared)
status_module (shared)
因此我尝试以下命令:
curl -i -s -k -v -X GET "http://localhost/vmportal/css"
结果是这样的:
HTTP/1.1 301 Moved Permanently
Date: Wed, 24 Nov 2021 06:32:01 GMT
Server: Apache/2.4.48 (Debian)
Location: http://localhost/vmportal/css/
Content-Length: 313
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://localhost/vmportal/css/">here</a>.</p>
<hr>
<address>Apache/2.4.48 (Debian) Server at localhost Port 80</address>
</body></html>
我难道不应该看到我在响应中设置的任何标题吗?
有人能告诉我我可能做错了什么吗?或者问题可能是什么?甚至如何调试?(如果您想知道的话,错误日志或访问日志中没有任何内容)。