【问题标题】:mod_rewrite and mod_proxy together in Apache configurationmod_rewrite 和 mod_proxy 在 Apache 配置中一起使用
【发布时间】:2019-10-12 15:43:05
【问题描述】:

我正在使用 Apache 服务器来托管我的 Angular 应用程序。所以我通过以下配置启用了单页应用程序支持

<Location / >
   RewriteEngine on#
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule . /index.html [L]
</Location>

我还有一个后端。我正在使用 mod_proxy 通过 Apache 代理它。

ProxyPass "/api" "http://127.0.0.1:8081/api"
ProxyPassReverse "/api" "http://127.0.0.1:8081/api"

但是当我同时使用这两种配置时,我无法调用任何 API。 所有调用都返回 index.html。

我可以知道什么是错误的以及如何解决它吗?

【问题讨论】:

  • 尝试再添加一个条件:RewriteCond %{REQUEST_URI} !^/api

标签: angular apache mod-rewrite mod-proxy


【解决方案1】:

感谢@Dusan Bajic 的评论。
现在,我有以下配置,它可以工作。

ProxyPass "/api" "http://127.0.0.1:8081/api"
ProxyPassReverse "/api" "http://127.0.0.1:8081/api"

<Location / >
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/api
    RewriteCond %{REQUEST_URI} !\.(?:css|js|map|jpe?g|gif|png)$ [NC]
    RewriteRule . /index.html [L]
</Location>

【讨论】:

    猜你喜欢
    • 2015-12-06
    • 1970-01-01
    • 1970-01-01
    • 2015-10-30
    • 2012-06-18
    • 2012-08-28
    • 2011-12-10
    • 1970-01-01
    • 2017-03-27
    相关资源
    最近更新 更多