Orthanc behind NGINX CORS Issue

Hi Everyone,

I have integrated OHIF Viewer with Meteor and here we used to upload Dicom i.e .dcm images to Orthanc Server. This is the basis procedure for this

  1. We upload a dicom file
  2. Orthanc Server is providing some REST APIs to store the images and it returns the generated URL.
  3. We store the returned URL in our DB for future use.

Now the Problem, We are using digital Ocean for hosting and both Orthanc server and our meteor Project is hosted on the same server. Both of them, running on different ports.
So, while displaying the stored image in Orthanc Server, I am getting CORS Error as

Failed to load http://siteName:8080/instances/af49dc5b-f0251/d27-ebbf0c68-3080fd96-e13e32c2/preview: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://sitename’ is therefore not allowed access.

Also, I have made changes in the sites-enable sitename.conf file as

server{
       listen  [::]:80;
       server_name sitename
       location  /orthanc/  {
                proxy_pass http://localhost:8080;
                proxy_set_header HOST $host;
                proxy_set_header X-Real-IP $remote_addr;
                rewrite /orthanc(.*) $1 break;
                add_header 'Access-Control-Allow-Credentials' 'true';
                add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,K$
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Origin' '*';
        }

}

The same is mentioned in the HOW CAN I RUN ORTHANC behind NGINX

Also, I have added this in main.js of server,

**WebApp.rawConnectHandlers.use(function(req, res, next) { res.setHeader("Access-Control-Allow-Origin", "*"); return next(); });**

but this also is not helping
Is there any solution for this CORS issue. Any help would be great

1 Like

I had a similar issue and tried in any possible way, until changing “localhost” to 127.0.0.1, and… it worked! Please give it a try.

location /orthanc/ {
proxy_pass http://127.0.0.1:8042;
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
rewrite /orthanc(.) $1 break;
add_header ‘Access-Control-Allow-Credentials’ ‘true’;
add_header ‘Access-Control-Allow-Headers’ ‘DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type’;
add_header ‘Access-Control-Allow-Methods’ ‘GET, POST, OPTIONS’;
add_header ‘Access-Control-Allow-Origin’ '
’;
}

1 Like