JIRA behind nginx proxy: hostname and url problems

Guillaume Maury October 14, 2011

Hi,

I'm trying to setup JIRA behind nginx. I'm getting problems with urls... For example when I try to go to the jira page instead of redirecting me to http://jira.example.com/secure/Dashboard.jspa it redirects me to http://jira.example.com/.example.com/secure/Dashboard.jspa

For reference here's my nginx configuration:

upstream jira {
  server 127.0.0.1:4800;
}


# the server directive is nginx's virtual host directive.
server {
  # port to listen on. Can also be set to an IP:PORT
  listen 80;
  
  # Set the max size for file uploads to 50Mb
  client_max_body_size 30M;

  # sets the domain[s] that this vhost server requests for
  server_name jira.example.com;

  # doc root
  root /opt/atlassian/jira/atlassian-jira;

  # vhost specific access log
  access_log  /var/log/nginx.jira.access.log  main;

  location / {
    # needed to forward user's IP address to rails
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_pass http://jira;
  }

}

At first the gadgets weren't working and I had the following error... 'jira' does not match expected hostname 'jira.example.com'

I fixed it by adding the following to conf/server.xml

< Connector port="8080" protocol="HTTP/1.1"  
      maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" useBodyEncodingForURI="true"  
      enableLookups="false" redirectPort="9443" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true"   
  
               proxyName="jira.example.com"  
               proxyPort="80" 
   />

What am I missing?

2 answers

1 vote
Guillaume Maury October 15, 2011

I found the issue, by default nginx tries to correct the redirect location from a proxy by replacing the proxied hostname with the correct hostname. The problem is that by setting proxyName, jira was redirecting to the correct hostname already which caused the problem.

So for example when going to http://jira.example.com it would send back a redirect to http://jira.example.com/secure/Dashboard.jspa which was replaced by nginx with .example.com/secure/Dashboard.jspa

The fix for this is to add proxy_redirect off; in the location / block.

0 votes
Victor Chirita February 16, 2017

Yep, that did the trick, thank you!

Suggest an answer

Log in or Sign up to answer