Web UI running from IIS

277 views
Skip to first unread message

Patrick van der Velde

unread,
May 25, 2015, 11:27:29 PM5/25/15
to consu...@googlegroups.com
Hi All

I'm trying to run the consul web UI from a local IIS instance so that I can (eventually) let IIS handle the authentication against the AD. The machine on which IIS runs has a consul agent running on it with the default http port but now the question is how do I point the UI to that local consul. I've tried setting up a redirect rule but to no avail. 

Setup:
My consul config is:

    {
      "data_dir": "c:\\ops\\consul\\akm\\data",
      
      "bootstrap_expect" : 1,
      "datacenter": "mydatacenter",
      "server": true,
      
      "domain": "mydomain",
      
      "addresses": {
        "dns": "<LOCAL_MACHINE_IP>"
      },
      "ports": {
        "dns": 8600,
        "http": 8500,
        "rpc": 8400,
        "serf_lan": 8301,
        "serf_wan": 8302,
        "server": 8300
      },
      
      "recursors": ["172.17.26.2"],
      
      "disable_remote_exec": true,
      "disable_update_check": true
    }

If I set the ui_dir option then it displays the UI without issues.

In IIS I've added the consul UI files to the consul sub-directory of the default website, i.e.

Default Web Site
    consul <-- UI files here

Things I've tried:
* Add a virtual v1 directory and then do a HTTP redirect to the http://localhost:8500/v1 URL
* Set a URL rewrite on the default website to redirect v1/* to http://localhost:8500/v1/{R:1}
* Set a URL redirect on the default website to redirect v1/* to http://localhost:8500/v1/{R:1}

Has anybody ever tried something like this? I saw a post from somebody trying this with nginx but I'm having lots of trouble translating to IIS / my situation so any hints would be appreciated.

Thanks

Petrik 


Ryan Uber

unread,
May 26, 2015, 2:11:13 PM5/26/15
to consu...@googlegroups.com
Hey Patrick,

The Consul UI has a few dedicated API endpoints which are only enabled when the "ui_dir" option is non-empty. I can see how this would be problematic while trying to use an external web server to serve the files, especially if you are using the external server for auth. What you could do as a work-around would be to point the "ui_dir" to some bogus directory. That way, Consul itself does not actually serve the UI, and the endpoints are enabled on the backend so that you can use them with another web server.

Another challenge as you have found is the server address. I am not an expert in the UI code, but from a cursory look through, it appears that the Consul agent address is assumed to be the same as the host address in the URL bar of your browser. This would mean that you would need to redirect all HTTP traffic for the Consul API to port 8500 on the consul agent. Your example above seems to be sufficient for this.

Give the "ui_dir" option a try and see if that get's you any further. Unfortunately, my knowledge of IIS is limited so I don't have the full picture of what's happening here.

- Ryan

Patrick van der Velde

unread,
May 26, 2015, 10:42:36 PM5/26/15
to consu...@googlegroups.com
Thanks for the hints.

After crawling through all the logs I could find I have managed to get it to work. Just in case somebody else would like to do this here's my current configuration:

* Using the default web site and having the consul agent http connection at localhost:8500
* I have the consul agent serve up the standard web UI stuff and then redirect to that in IIS
* IIS rewrite config section looks like:

    <rewrite>
        <rules>
            <rule name="Reverse Proxy to Consul UI" enabled="true" stopProcessing="true">
                <match url="consul/(.*)" />
                <conditions>
                    <add input="{CACHE_URL}" pattern="^(https?)://" />
                </conditions>
                <serverVariables>
                    <set name="HTTP_ACCEPT_ENCODING" value="" />
                </serverVariables>
                <action type="Rewrite" url="{C:1}://localhost:8500/ui/{R:1}" logRewrittenUrl="false" />
            </rule>
            <rule name="Reverse Proxy to Consul API" enabled="true" stopProcessing="true">
                <match url="v1/(.*)" />
                <conditions>
                    <add input="{CACHE_URL}" pattern="^(https?)://" />
                </conditions>
                <serverVariables>
                    <set name="HTTP_ACCEPT_ENCODING" value="" />
                </serverVariables>
                <action type="Rewrite" url="{C:1}://localhost:8500/v1/{R:1}" logRewrittenUrl="false" />
            </rule>
        </rules>
    </rewrite>


Next thing I have to figure out is auth but that is a IIS issue I think

Thanks

Saravanan Palanivel

unread,
Nov 28, 2018, 9:26:13 AM11/28/18
to Consul
I'm trying with consul version 1.4.0 on windows 10 and below mentioned rewrite config, but seems like its not working. Getting 404 not found error. 

Any help on this would be really appreciated! 


thanks!
Saravanan
Reply all
Reply to author
Forward
0 new messages