我的服务器上有一个应用程序,它大部分时间都在覆盖 Apache。现在我想在我的 VPS 上安装 PhpMyAdmin,但它不起作用(显示目录列表而不是 UI),但通过询问几个网站并反复试验,我意识到我正在尝试通过我的应用程序 (Traccar) 而不是 Apache 来运行 PhpMyAdmin。
现在回到主题。我在 Ubuntu Server 18.04 上,并且具有以下站点配置:
Listen 80
<IfModule mod_ssl.c>
<VirtualHost *:80>
ServerName x.example.com
Redirect / https://x.example.com
</VirtualHost>
<VirtualHost *:443>
ServerName x.example.com
DocumentRoot /var/www/html
ServerAdmin admin@localhost
ProxyPass /api/socket ws://localhost:app_port/api/socket
ProxyPassReverse /api/socket ws://localhost:app_port/api/socket
ProxyPass /phpmyadmin !
ProxyPass / http://localhost:app_port/
ProxyPassReverse / http://localhost:app_port/
SSLEngine on
SSLOptions +StrictRequire
SSLProtocol TLSv1
ServerAlias x.example.com
SSLCertificateFile /etc/letsencrypt/live/x.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/x.example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
我希望它工作的方式:
如果我连接到x.example.com我被重定向到我的应用程序。运行正常。
如果我连接到x.example.com/phpmyadmin我想接收 PhpMyAdmin UI。但我收到的是“重定向次数过多”错误。
当我访问 phpmyadmin 目录时,重写日志不断在服务器日志中的这两条消息之间交替出现:
[Fri May 10 10:32:38.733370 2019] [rewrite:trace1] [pid 19228] mod_rewrite.c(482): [client xxx.xxx.xxx.xxx:yyyy] xxx.xxx.xxx.xxx - - [x.example.com/sid#7f34cd331cc0][rid#7f34cd2640a0/initial] pass through /phpmyadmin
[Fri May 10 10:32:38.767398 2019] [rewrite:trace2] [pid 19228] mod_rewrite.c(482): [client xxx.xxx.xxx.xxx:yyyy] xxx.xxx.xxx.xxx - - [x.example.com/sid#7f34cd331cc0][rid#7f34cd2620a0/initial] init rewrite engine with requested uri /phpmyadmin
这是我到达时收到的x.example.com/phpmyadmin:
--2019-05-10 10:43:19-- https://x.example.com/phpmyadmin
Resolving x.example.com (x.example.com)... xxx.xxx.xxx.xxx
Connecting to x.example.com (x.example.com)|xxx.xxx.xxx.xxx|:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://x.example.com/phpmyadmin [following]
--2019-05-10 10:43:19-- https://x.example.com/phpmyadmin
Reusing existing connection to x.example.com:443.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://x.example.com/phpmyadmin [following]
--2019-05-10 10:43:19-- https://x.example.com/phpmyadmin
Reusing existing connection to x.example.com:443.
这些线路不断重复,直至达到 20 次重定向。
如果我卷曲x.example.com/phpmyadmin我明白了:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
<title>302 Found</title>
</head>
<body>
<h1>Found</h1>
<p>The document has moved <a href="https://x.example.comphpmyadmin">here</a>.</p>
<hr>
<address>Apache/2.4.29 (Ubuntu) Server at x.example.com Port 80</address>
</body>
</html>
答案1
答案非常简单。我忘记在 apache2.conf 中留下了永久重定向规则 - 这导致了无限循环。从 apache 配置中删除该行解决了我的问题。感谢所有参与的人。