Apache,使用位置将某个端点路由到其他端口时出现问题

vyu0f0g1  于 2023-01-17  发布在  Apache
关注(0)|答案(2)|浏览(132)

我尝试将以/API/开头的所有链接路由到服务器上的端口3002,但它们总是路由到3008。例如,https://example.com/api/customers应代理/路由到localhost:3002

<VirtualHost *:443>
    ServerAdmin (redacted)
    ServerName (redacted)
    ServerAlias (redacted)

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/(redacted)/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/(redacted)/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/(redacted)/chain.pem

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Location "/api\/(.*)/">
        ProxyPass http://localhost:3002/
        ProxyPassReverse http://localhost:3002/
    </Location>

    <Location "/">
        ProxyPass http://localhost:3008/
        ProxyPassReverse http://localhost:3008/
    </Location>
</VirtualHost>

使用此配置转到domain.com可以工作并显示我的网站,但domain.com/api/customers从端口3008上的webapp返回错误,因此它没有被正确路由(它应该转到3002)。
端口3008和3002上的应用程序运行正常,所以这不是问题所在。我试着在配置文件中将domain/ first和domain/API last放在一起,但似乎没有解决问题。配置文件已启用
我尝试了不同的正则表达式来匹配API端点,但是这个应该可以
Apache正在侦听端口443
启用了这些mods,这应该是需要的:代理模块(共享)代理http模块(共享)代理wstunnel模块(共享)
如果你需要更多的信息请告诉我

t30tvxxf

t30tvxxf1#

修改您的配置如下,并尝试.
发布访问日志和curl响应(如果不工作)。
curl -ILKv https://domain.name/api/anything
curl -ILKv https://domain.name/api
https://httpd.apache.org/docs/2.4/mod/mod_proxy.html

ProxyRequests Off
<Proxy *>
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
</Proxy>
ProxyPass /api http://localhost:3002
ProxyPassReverse /api http://localhost:3002
juzqafwq

juzqafwq2#

我最后是这样解决的:

RewriteEngine  on
RewriteRule "/api\/(.*)" "http://localhost:3002/api/$1" [P] 

<Location "/">
    ProxyPass http://localhost:3008/
    ProxyPassReverse http://localhost:3008/
</Location>

相关问题