how to proxy rewrite but preserve url

May 21, 2015 921 views
Docker Dokku

I am totally new to this proxy stuff so bear with me and may not be using the right terminology

We have setup a proxy to our ec2 instance where we have a few dokku/docker containers that are hosting a few apps. the url for those apps are:

We would like to be able to have users only type:

we've setup a rewrite for the above urls which works fine.
http://foo.abc.domain.com -> http://foo.dokku.abc.domain.com
http://bar.abc.domain.com -> http://bar.dokku.abc.domain.com

however we would like it to not actually rewrite the url, we'd like it to preserve the url in the browser.

What can we do to fix this?


below is the code in /etc/nginx/sites-available/default

server {
        listen 80 ;

        server_name .dokku.abc.domain.com;

        location / {
                proxy_pass http://ip-aaa-bbb-ccc-ddd.us-west-1.compute.internal:80;
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

server {
        listen 80 ;

        server_name foo.abc.domain.com;
        rewrite ^(.*) http://foo.dokku.abc.domain.com;
server {
        listen 80 ;

        server_name bar.abc.domain.com;
        rewrite ^(.*) http://bar.dokku.abc.domain.com;
1 Answer

Instead of a rewrite for your domains you can use a proxy_pass configuration like the one in your .dokku.abc.domain.com configuration. There is no need from what I can see to redirect the user before initiating the proxy. You will also need to make sure that your app itself does not have the other domain name configured or hard-coded into it anywhere as a mismatch in paths or the domain could cause issues.

Have another answer? Share your knowledge.