背景
在ubuntu系统上部署Gerrit时看了许多网上的教程,但是自己在部署apache2反向代理的时候,打开网页后报错如下:
Configuration Error
Check the HTTP server's authentication settings.
The HTTP server did not provide the username in the Authorization header when it forwarded the request to Gerrit Code Review.
If the HTTP server is Apache HTTPd, check the proxy configuration includes an authorization directive with the proper location, ensuring it ends with '/':
<VirtualHost 127.0.0.1:8081>
ServerName 127.0.0.1
ProxyRequests Off
ProxyVia Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location /login/>
AuthType Basic
AuthName "Gerrit Code Review"
Require valid-user
...
</Location>
AllowEncodedSlashes On
ProxyPass / 127.0.0.1 nodecode
</VirtualHost>
其实问题就出在apache2的配置文件httpd.conf没有生效,没看到网上有很好的解决办法,于是自己整理了一下思路,记录了一下配置apache2的反向代理过程。
apache2配置文件增加方法
如果您想要增加一个和 000-default.conf
功能类似的配置文件,并且想要将其作为默认配置,您可以按照以下步骤进行配置:
-
创建新配置文件: 在
/etc/apache2/sites-available/
目录中创建一个新的配置文件,例如my-default.conf
。sudo nano /etc/apache2/sites-available/my-default.conf
-
复制
000-default.conf
的内容: 打开000-default.conf
文件,复制其内容,然后粘贴到新创建的my-default.conf
文件中。 -
修改配置: 根据您的需求,您可以修改新配置文件中的设置。例如,您可以更改默认文档(
DirectoryIndex
)、错误页(ErrorDocument
)、服务器名称(ServerName
)等。 -
启用新配置文件: 创建一个指向
my-default.conf
文件的符号链接,并将其放在/etc/apache2/sites-enabled/
目录中。sudo ln -s /etc/apache2/sites-available/my-default.conf /etc/apache2/sites-enabled/
-
重启 Apache 服务: 确保新配置文件被加载,您可以重启 Apache 服务。
sudo systemctl restart apache2
-
检查配置: 使用
systemctl status apache2.service
命令检查 Apache 服务的状态,确保它正在运行。sudo systemctl status apache2.service
-
测试新配置: 通过访问您的服务器 IP 地址或主机名来测试新配置。确保请求被正确处理。
请注意,如果您使用的是 000-default.conf
文件,Apache 会自动处理默认配置。如果您想要覆盖这个默认配置,您需要确保新配置文件位于 /etc/apache2/sites-enabled/
目录中,并且没有被禁用。此外,如果您修改了默认文档或错误页,您可能需要重启 Apache 服务以使更改生效。
配置效果
修改前:
修改后:
到这里,Gerrit就可以成功打开了: