【问题标题】:NGINX rewrite to Apache Mod-RewriteNGINX 重写为 Apache Mod-Rewrite
【发布时间】:2019-12-19 16:47:05
【问题描述】:

我正在将反向代理从 NGINX 迁移到 Apache,但不知道如何将 nginx 重写转换为 Apache mod 重写。

这是我的 nginx 配置的相关部分:

    server { 
    listen           443 ssl;
    server_name localhost;


    #### REWRITE FOR APP PROXY ###
    rewrite ^/app-proxy/([^/]+?)/([^/]+?)/(.*)$ /$2/$1/$3 last;


    #### Final destination, SAL-ASSETS (STATIC FILES)
    location /sal-assets/ {
        alias       /var/www/sal-assets/;
        expires 30d;
    }

    #### Final destination TOMCAT & NG SERVE
    location / {
        proxy_pass          http://localhost:8080;
    }

    location /sal-frontnd/ {
        proxy_pass          http://localhost:4200;
    }

    location /sal-backend/ {
        proxy_pass          http://localhost:4200;
    }

}

这是我目前对 Apache 的了解:

ProxyPass               /sal-frontend/     http://localhost:4200/sal-frontend/
ProxyPassReverse        /sal-frontend/     http://localhost:4200/sal-frontend/
ProxyPass               /sal-admin/     http://localhost:4200/sal-admin/
ProxyPassReverse        /sal-admin/     http://localhost:4200/sal-admin/
ProxyPass               /sal-backend/     http://localhost:8080/
ProxyPassReverse        /sal-backend/     http://localhost:8080/

<Directory "C:/xampp/htdocs">
RewriteEngine on
RewriteRule rewrite ^/app-proxy/([^/]+?)/([^/]+?)/(.*)$ /$2/$1/$3

很遗憾,我的重写规则似乎被打破了?

AH00526: Syntax error on line 253 of C:/xampp/apache/conf/httpd.conf:
RewriteRule: bad flag delimiters

希望有任何提示。

【问题讨论】:

  • 首先,从RewriteRule 行中删除rewrite
  • 也许这个工具可以帮助你labs.gidix.de/nginx
  • 欣赏nginx转换器,但效果不是很好。 :)

标签: apache nginx mod-rewrite


【解决方案1】:

以下终于对我有用:

<Directory />
RewriteEngine On
AllowOverride All
Require all denied
RewriteRule /app-proxy/([^/]+?)/([^/]+?)/(.*) /$2/$1/$3 [L,NC]
</Directory>
  • 按照 Dusan 的建议,从 RewriteRule 行中删除“rewrite”
  • 从移动到
  • 设置 AllowOverride All
  • 从正则表达式中删除 ^ 和 $,以便我们拥有 /app-proxy/([^/]+?)/([^/]+?)/(.*)
  • 添加 [L,NC]

【讨论】:

    猜你喜欢
    • 2014-03-16
    • 1970-01-01
    • 2019-09-13
    • 1970-01-01
    • 2011-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    相关资源
    最近更新 更多