Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.