Apache - Nginx重写规则

时间:2017-03-08 22:03:35

标签: nginx

我遇到了Apache" Rewrite"到Nginx转换。

RewriteCond %{HTTP_HOST} ^new\.app17web\.dev1\.whispir\.net             [NC]
RewriteCond %{REQUEST_URI} !^/s/                                                [NC]
RewriteCond %{REQUEST_URI} !^/jsp/                                    [NC]
RewriteRule .* /jsp/portal/404/austpost/index.html

RewriteCond %{HTTP_HOST} ^new2\.app17web\.dev1\.whispir\.net            [NC]
RewriteCond %{REQUEST_URI} !^/s/                                                [NC]
RewriteCond %{REQUEST_URI} !^/jsp/                                    [NC]
RewriteRule .* /jsp/portal/404/austpost/index.html

I have in my Nginx config :
    location / {

    if ($http_host ~ "^new.app17web.dev1.whispir.net"){
    set $rule_0 1$rule_0;
    }

    if ($uri !~ "^/s/"){
    set $rule_0 2$rule_0;
    }

    if ($uri !~ "^/jsp/"){
    set $rule_0 3$rule_0;
    }

    if ($rule_0 = "321"){
    rewrite /.* /jsp/portal/404/austpost/index.html;
    }

    if ($http_host ~ "^new2.app17web.dev1.whispir.net"){
    set $rule_0 1$rule_0;
    }

    if ($uri !~ "^/s/"){
    set $rule_0 2$rule_0;
    }

    if ($uri !~ "^/jsp/"){
    set $rule_0 3$rule_0;
    }

    if ($rule_0 = "321"){
    rewrite /.* /jsp/portal/404/austpost/index.html;
    }

      try_files $uri @mainWorker;
    }

我的@mainWorker是:

    location @mainWorker {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
        proxy_pass  http://mainWorker;

    }

我也有一个proxy.conf

underscores_in_headers  on;
proxy_intercept_errors  on;
proxy_redirect         off;
client_max_body_size    10m;
client_body_buffer_size 128k;
proxy_connect_timeout   90;
proxy_send_timeout      90;
proxy_read_timeout      90;
proxy_buffers           32 4k;

我得到的是:

禁  您的访问权限不允许您访问此内容。  您请求的信息已不再可用或已过期。  请返回您到达的页面,或返回Whispir登录页面。 如果我没有重写,一切正常,但当我加入时,我会被禁止。

是否有人可以指出我的配置错误。

感谢。      ģ

1 个答案:

答案 0 :(得分:0)

我想我发现了这个问题。 位置块中的if语句指向上游,检查/jsp/portal/404/austpost/index.html; ,这不是上游,它是Nginx服务器的本地。

所以把if语句从位置/块中删除,一切正常。

做了太多的假设,它是上游到我的Jboss服务器。

感谢您的回顾。

ATB。