Configure Nginx 1.2 as proxy for Jira 5

By default Jira runs on a certain port, in this example at port 8090. It is accessible by http://example.com:8090/. This tutorial will make the Jira application available at port 80 with jira as path like: http://example.com/jira. Two configurations are possible, with or without SSL.

Make sure you perform all actions as root.

Without SSL

Change the file /opt/atlassian/jira/conf/server.xml file with:

nano /opt/atlassian/jira/conf/server.xml

Search for the part <Service name=”Catalina”> and make it look like:

<Service name="Catalina">

        <Connector port="8090"

                  maxThreads="150"
                  minSpareThreads="25"
                  connectionTimeout="20000"

                  enableLookups="false"
                  maxHttpHeaderSize="8192"
                  protocol="HTTP/1.1"
                  useBodyEncodingForURI="true"
                  redirectPort="8443"
                  acceptCount="100"
                  disableUploadTimeout="true"

                  scheme="http"
                  proxyName="example.com"
                  proxyPort="80"
       />

This part is added:

                   scheme="http"
                   proxyName="example.com"
                   proxyPort="80"

Configure Nginx as proxy

nano /etc/nginx/conf.d/example.com.conf
server {
    server_name example.com;

    location ^~ /jira {
        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://localhost:8090;
    }
}

Continue by following the chapter Steps for both “Without SSL” and “With SSL”.

With SSL

Change the file /opt/atlassian/jira/conf/server.xml file with:

nano /opt/atlassian/jira/conf/server.xml

Search for the part <Service name=”Catalina”> and make it look like:

<Service name="Catalina">

        <Connector port="8090"

                  maxThreads="150"
                  minSpareThreads="25"
                  connectionTimeout="20000"

                  enableLookups="false"
                  maxHttpHeaderSize="8192"
                  protocol="HTTP/1.1"
                  useBodyEncodingForURI="true"
                  redirectPort="8443"
                  acceptCount="100"
                  disableUploadTimeout="true"

                  scheme="https"
                  proxyName="example.com"
                  proxyPort="443"
       />

This part is added:

                   scheme="https"
                   proxyName="example.com"
                   proxyPort="443"

Configure Nginx as proxy

nano /etc/nginx/conf.d/example.com.conf
server {
    server_name example.com;

    listen 80;
    listen 443 ssl;
    ssl_certificate      /etc/ssl/certs/example_com.pem;
    ssl_certificate_key  /etc/ssl/private/example_com.key;

    location ^~ /jira {
        if ($ssl_protocol = "") {
            return 301 https://$server_name$request_uri;
        }

        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://localhost:8090;
    }
}

Continue by following the chapter below Steps for both “Without SSL” and “With SSL”.

Steps for both “Without SSL” and “With SSL”

Make the node “host” in the file above look like below. The value “/jira” is added to the path attribute of the node “Context”.

<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">

                <Context path="/jira" docBase="${catalina.home}/atlassian-jira" reloadable="false" useHttpOnly="true">


                    <!--
                    ====================================================================================

                    Note, you no longer configure your database driver or connection parameters here.
                    These are configured through the UI during application setup.

                    ====================================================================================
                   -->

                    <Resource name="UserTransaction" auth="Container" type="javax.transaction.UserTransaction"
                             factory="org.objectweb.jotm.UserTransactionFactory" jotm.timeout="60"/>
                    <Manager pathname=""/>
                </Context>

</Host>

Restart Jira:

service jira stop
service jira start

Reload nginx

service nginx reload

Everything should be working now if you visit http://example.com/jira. You will probably get a message at the top of the page that you visit Jira from another URL than the set base URL. The proposed link to change the base URL will be: http://example.com/jira/secure/admin/EditApplicationProperties!default.jspa. Change the base URL there from http://example.com:8090 to http://example.com/jira or https://example.com/jira.

Tags: ,,