【发布时间】:2018-11-10 04:44:37
【问题描述】:
我无法将某些请求重定向到其他端口。这是我的配置:
- 我有一个像 XXXX.ddns.net 这样的公共域
- 我有一个带有 apache 的 Rapsbian 服务器,并且我的 /var/www 文件夹中的文件得到了正确的服务(角度网站)
- 在同一个 Raspbian 服务器上,有一个 REST 服务器在 3000 端口上运行
- 这是在带有 SSL(letsencrypt) 的 HTTPS 上运行的
我希望所有对 XXXX.ddns.net/api/* 的请求都重定向到 3000 端口。
我更改了 .htaccess 文件,重写规则似乎在本地工作,但我无法在我的互联网站点上工作。 API 请求实现时出现错误 500。
这是我当前的 .htaccess 文件:
RewriteEngine On
RewriteRule ^api/(.*) https://localhost:3000/api/$1 [QSA]
# not sure if it should be http or https in the rule but nothing works
#RewriteRule ^api/(.*) http://localhost:3000/api/$1 [QSA]
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested pattern is file and file doesn't exist, send 404
RewriteCond %{REQUEST_URI} ^(\/[a-z_\-\s0-9\.]+)+\.[a-zA-Z]{2,4}$
RewriteRule ^ - [L,R=404]
这是我当前的 000-default-le-ssl.conf 文件(在 /etc/apache2/sites-available 中):
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ServerName XXXX.ddns.net
SSLCertificateFile /etc/letsencrypt/live/XXXX.ddns.net/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/XXXX.ddns.net/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
<Location /api>
ProxyPass http://127.0.0.1:3000/api
ProxyPassReverse http://127.0.0.1:3000/api
</Location>
</VirtualHost>
</IfModule>
如果有人可以帮助我实现它... 谢谢!
【问题讨论】:
-
我不熟悉letsencrypt。日志文件中有任何内容吗?有关详细信息,请参阅“systemctl status apache2.service”和“journalctl -xe”。如果您总是想要 HTTPS,只需在端口 80 处添加第二个虚拟主机,并使用指令
redirect permanent / https://yourserver.url/。 -
我试过了,但没有任何改变。当我的网站联系 api 部分时,出现错误 500。如果我直接在 3000 端口上发出我的 api 请求,它可以工作,但它并不优雅,并且几乎被所有防火墙阻止......还有其他想法吗?
-
如果它不起作用,您可以使用命令
systemctl status apache2.service和journalctl -xe与sudo或root获得有关问题所在的线索。你这样做了吗?