Issue with Redirects After Adding SSL Certificate to XNAT

103 views
Skip to first unread message

Ruba

unread,
Nov 21, 2024, 10:21:41 AM11/21/24
to xnat_discussion

Dear all,

I recently added an SSL certificate to XNAT. However, when I try to log in using https://domain/Login.vm#!, it always redirects me to the HTTP URL (shows "unable to connect"). Manually changing the URL back to HTTPS allows me to access the home page. A similar issue occurs when logging out—an "unable to connect" error is displayed and redirect to the http url.

The nginx configuration is here:

server {
    listen 443 ssl;
    #listen 80;
    server_name domain_name;

    ssl_certificate     /etc/ssl/certs/2024/cert.pem;
    ssl_certificate_key /etc/ssl/private/2024/cert.key;

    location / {
        proxy_pass                          http://localhost:8080;
        proxy_redirect http://localhost:8080 https://$host;
        #proxy_redirect                      http://localhost:8080 $scheme://localhost;
        proxy_set_header Host               $host;
        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_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-Port 443;
        proxy_connect_timeout               150;
        proxy_send_timeout                  100;
        proxy_read_timeout                  100;
        proxy_buffers                       4 32k;
        client_max_body_size                0;
        client_body_buffer_size             128k;
    }
}

Could you please assist with resolving this redirect issue?

Thank you.

Best,

Ruba

Chidi Ugonna

unread,
Nov 21, 2024, 12:15:06 PM11/21/24
to xnat_discussion
Hi Ruba, you can try and add another server entry in the nginx configuration to redirect http traffic. something like where 192.138.10.1 is your server url.

server {
listen 80 default_server;
listen [::]:80 default_server;
server_name 192.138.10.1;
return 301 https://$server_name$request_uri;
}

Ruba

unread,
Nov 21, 2024, 12:39:24 PM11/21/24
to xnat_discussion

Thank you, Chidi.

I have added that section to the config file, but using the default_server parameter caused Nginx to fail loading, so I omitted it. The updated section is as follows. Unfortunately, I am still getting the same error.

server {
     listen 80;
     server_name domain.xnat.ca;
     return 301 https://$server_name$request_uri;

}
server {
    listen 443 ssl;
    #listen 80;
    server_name fdopa.nan.kcl.ac.uk;

    ssl_certificate     /etc/ssl/certs/2024/fdopa_nan_kcl_ac_uk.pem;
    ssl_certificate_key /etc/ssl/private/2024/fdopa_nan_kcl_ac_uk.key;

Amr Bassam Shadid

unread,
Nov 21, 2024, 12:55:53 PM11/21/24
to xnat_discussion
Hi Ruba,

Based on your description, the issue likely stems from XNAT's internal security settings rather than just the NGINX configuration.

To resolve this, you can update XNAT's security settings as follows:
Log into XNAT as an Admin ->
Go to Administer > Site Administration.
In the left-hand menu, select the Security section.
Locate the option for "Security Channel".
Change the setting to either:
https (recommended): Forces all traffic to use HTTPS.
any (alternative): Allows both HTTP and HTTPS traffic 
Save Changes
Click Save or Apply to confirm the update.

If your NGINX configuration is already set up with HTTP-to-HTTPS redirection (as shown in your example), this change in XNAT should address the issue.

Best,
Amr

Ruba

unread,
Nov 21, 2024, 1:03:54 PM11/21/24
to xnat_discussion
Thank you, Amr. 

I have already tried that, but selecting 'https' option resulted in being unable to load the application. I came across a post in this group mentioning that it could be an issue because Tomcat doesn’t handle SSL directly.

Best,
Ruba

Chidi Ugonna

unread,
Nov 21, 2024, 1:16:10 PM11/21/24
to xnat_discussion
Hi Ruba,
We have XNAT set up to use http and https. I notice some differences between your nginx configuration and ours. See below where the domain name is mydomain1.university .edu - hope you can get your setup working the way you want!

server {
  listen 443 ssl;
  server_name mydomain1.university.edu;
  ssl on;
  ssl_session_cache builtin:1000 shared:SSL:10m;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
  ssl_prefer_server_ciphers on;
  ssl_certificate /path/to/domain.pem;
  ssl_certificate_key /path/to/domain.pem;

  location / {
   proxy_redirect off;
   proxy_set_header Host $host;
   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_connect_timeout 600;
   proxy_send_timeout 600;
   proxy_read_timeout 600;
   send_timeout 600;
   proxy_buffers 4 32k;
   client_max_body_size 0;
   client_body_buffer_size 128k;
  }

  access_log /var/log/nginx/xnat.access.log;
  error_log /var/log/nginx/xnat.error.log;
}

server {
  listen 80 default_server;
  listen [::]:80 default_server;
  server_name mydomain1.university.edu;
  return 301 https://$server_name$request_uri;
}

Rick Herrick

unread,
Nov 21, 2024, 4:30:50 PM11/21/24
to xnat_di...@googlegroups.com

Ruba, make sure you’ve set the site URL to the https version of the URL. If it’s still http://blah that would explain why it’s redirecting to that address rather than the secure version.

 

--
You received this message because you are subscribed to the Google Groups "xnat_discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xnat_discussi...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/xnat_discussion/e44b2160-2085-4731-a7b1-f883cbf8f74cn%40googlegroups.com.

Ruba

unread,
Nov 21, 2024, 5:43:58 PM11/21/24
to xnat_discussion
Hi Chidi and Rick,

Thank you for your input. I have already updated the site URL through the admin panel.

However, I am still encountering this issue where the link http://domain-name/app/template/Login.vm appears whenever I try to log in or log out of the system. So far, I have only made changes to the /etc/nginx/sites-enabled/xnat file. Are there any other configurations I should update?

Thank you for your guidance.

Best regards,
Ruba

Ruba

unread,
Nov 22, 2024, 3:40:52 AM11/22/24
to xnat_discussion

Hi all,

Thank you for your help.

I just wanted to share the solution I found for this problem, in case others face something similar. The issue was related to configuring Tomcat to communicate with Nginx over HTTP while Nginx handles SSL termination. Here's what I did:

1. Updated the HTTP <Connector> in server.xml:

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="443"
           proxyName="your-domain.com"
           proxyPort="443" />

2. Configured RemoteIpValve to handle forwarded headers:

I added the following under the <Host> section in server.xml to ensure Tomcat correctly interprets forwarded headers from Nginx:

<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
    <Valve className="org.apache.catalina.valves.RemoteIpValve"
           remoteIpHeader="x-forwarded-for"
           protocolHeader="x-forwarded-proto"
           protocolHeaderHttpsValue="https" />
</Host>

After making these changes and restarting Tomcat and Nginx, everything worked as expected.

Best regards,

Ruba

Carlos A

unread,
11:51 AM (6 hours ago) 11:51 AM
to xnat_discussion
Hi,

I am facing this issue in the Docker version, but I could not manage to solve this problem using your advices.

My settings are the same than Ruba's

Any advice on this?

Regards

Carlos A

unread,
12:05 PM (6 hours ago) 12:05 PM
to xnat_discussion
Hi,

I managed to solve this issue by including the scheme in the Connector.

<Connector port="8080" protocol="HTTP/1.1"
...
               proxyName="..."
               proxyPort="443"
               scheme="https" 

Reply all
Reply to author
Forward
0 new messages