1

I'm trying to write a rewrite rule for Zimbra, which will allow me to use a hostname to access the Zimbra Desktop Web UI instead of the IP address and port.

The default Zimbra URLs are like this:

http://127.0.0.1:port/?at=long-encrypted-user-id
http://127.0.0.1:port/zimbra/?at=long-encrypted-user-id
http://127.0.0.1:port/desktop/login.jsp?at=long-encrypted-user-id

Here's what I have till now:

server {
    server_name hostname;
    location / {
            proxy_redirect                   off;
            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_pass                       http://127.0.0.1:port/;
    }
}

This only replaces http://hostname by http://127.0.0.1:port in the background; Where I'm stuck is adding the ?at=long-encrypted-user-id to the URLs. Can somebody help?

Yusuf
  • 205
  • 3
  • 11

1 Answers1

0

OK, so if anyone needs this in the future, I just had to add an if and a rewrite:

if ($args !~* at=long\-encrypted\-user\-id) {
    rewrite ^/(.*)$ /$1?at=long-encrypted-user-id last;
}

and the final server block becomes

server {
    server_name hostname;
    location / {
        proxy_redirect                   off;
        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_pass                       http://127.0.0.1:port/;
        if ($args !~* at=long\-encrypted\-user\-id) {
            rewrite ^/(.*)$ /$1?at=long-encrypted-user-id last;
        }
    }
}

Nginx warns against using if(IfIsEvil), but not if you add last to the rewrite.

Yusuf
  • 205
  • 3
  • 11