'localhost', does not match expected hostname with basic Caddy reverse proxy

Barnaby Keene May 3, 2017

I've managed to get Jira up on my server now, it's a vanilla installation straight from the install docs running on port 8990 and connected to a postgres db on localhost.

My reverse proxy is Caddy, it simply redirects http://jira.mydomain to http://localhost:8990 (no SSL, that looks like a nightmare to set up, one of the reasons I use Caddy is the automated SSL - but I won't bother with that right now).

I first got the baseurl error which I fixed. Now I'm getting this other error which seems like its trying to use localhost for every reletive address.

The dashboard shows the `UrlHostnameMismatchException` but I've tried to set the hostname URL via server.xml:

<Engine name="Catalina" defaultHost="jira.mydomain">
    <Host name="jira.mydomain" appBase="webapps" unpackWARs="true" autoDeploy="true">
        <Context path="" docBase="${catalina.home}/atlassian-jira" reloadable="false" useHttpOnly="true">

Restarted and still the same error. How on earth do I fix this? Do I have to modify the Caddy config to do something or change the Jira config?

I'd rather not install another proxy just for Atlassian apps, Caddy does a great job for my existing services and the painless HTTPS support is great.

1 answer

1 accepted

1 vote
Answer accepted
Barnaby Keene May 3, 2017

I figured it out straight after, but maybe this will be useful. If you're a Caddy reverse-proxy user and you stumbled upon this, I hope it helps!

The solution is to add a `proxyName` and `proxyPort` attribute to the `<Connector>` object:

<Connector port="8990"
    maxThreads="150"
    minSpareThreads="25"
    connectionTimeout="20000"

    proxyName="jira.mydomain"
    proxyPort="80"

Annoyingly, this information was buried in Apache specific documentation whereas it's software-agnostic when it comes to reverse proxy applications.

I'm now going to try HTTPS with Caddy's auto-installed certs and update this response...

Barnaby Keene May 3, 2017

SSL with Caddy's auto-install was simpler than I thought!

Just add the `scheme` field alongside `proxyName`, set `proxyPort` to 443 and modify your Caddyfile to use https.

    ...
    proxyName="jira.mydomain"
    proxyPort="433"
scheme="https"
Lars Olav Velle
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 3, 2017

You might also want to add:

secure="true"

Barnaby Keene May 3, 2017

Oh yeah I forgot to mention, I was looking for documentation on that attribute but couldn't find any. What does it actually mean?

Andrew Barton September 12, 2020

Just to provide additional clarity, the modifications referenced are for the tomcat server.xml. 

This answer helped me, but required slight modifications based on this thread (as I am running docker instance):

https://community.atlassian.com/t5/Jira-questions/How-to-use-a-custom-server-xml-on-Jira-Docker-image/qaq-p/1166929

If you are also using Docker, this folder location should be persisted:

https://community.atlassian.com/t5/Jira-Software-questions/How-to-run-jira-software-docker-with-HTTPS/qaq-p/1148354

Thanks for your prompt response.  After reading instructions, I am putting both directory in volumes 

 

 volumes:    

jira-home-data:/var/atlassian/application-data/jira    

jira-app-data:/opt/atlassian/etc/

Suggest an answer

Log in or Sign up to answer