question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid redirect when accessing ATLAS on a URL not ending in a trailing slash

See original GitHub issue

Expected behavior

When running the atlas container exposed on a port other than 8080 or when accessing the container from a reverse proxy and the /atlas URL does not end in a trailing slash, one should still be able to see the ATLAS UI.

Actual behavior

The nginx server responds with a redirect to the server host and port with the trailing slash added to the URL. This seems to be a common issue: https://serverfault.com/questions/739498/nginx-rewrite-on-docker-machine-when-host-port-container-port

I was able to resolve it by using the following /etc/nginx/default.conf:

server {
    listen       8080;

    root /usr/share/nginx/html;

    location ~ ^.*[^/]$ {
        try_files $uri @rewrite;
    }

    location @rewrite {
        return 302 $scheme://$http_host$uri/; # <- this uses the request header ('Host:') to determine the hostname+port
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

If it seems reasonable, I can create a PR for this.

Steps to reproduce behavior

  1. docker run --rm -it -p 9090:8080 ohdsi/atlas:2.10.1
curl -vvv localhost:9090/atlas
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9090 (#0)
> GET /atlas HTTP/1.1
> Host: localhost:9090
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Server: nginx/1.20.1
< Date: Fri, 26 Nov 2021 11:09:30 GMT
< Content-Type: text/html
< Content-Length: 169
< Location: http://localhost:8080/atlas/ # <---- see here
< Connection: keep-alive
<
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.20.1</center>
</body>
</html>
* Connection #0 to host localhost left intact
  1. thus this would redirect to localhost on port 8080 but the container is exposed on port 9090

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
chglcommented, May 5, 2022

@chgl - I’m unclear on what you’d propose to change in the ATLAS code base to address the issue? You are welcome to submit a PR and we’ll review it…I’m just not sure what is easier (describe vs. code a PR to propose the change).

@anthonysena Ah sorry, to clarify: it would just mean adding a custom nginx.conf to the container when it is build - I’ll go ahead and create a PR.

0reactions
iamalonsocommented, May 5, 2022

@iamalonso see the code snippet below

I was able to resolve it by using the following /etc/nginx/default.conf:

I mounted that configuration inside the container as /etc/nginx/default.conf.

I’d be happy to create a PR and set it as the default config if any of the maintainers give their ok.

Thanks for your reply @chgl

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix internal redirects from trailing slash mismatch?
This issue means that the one URL on your site is redirected to another internal URL. The presence/absence of a trailing slash is...
Read more >
How to force https, www and a trailing slash with one redirect
The right way is to make the .htaccess check for the / then check for www. and https:// . If any of our...
Read more >
Should You Have a Trailing Slash at the End of URLs? - Ahrefs
A trailing slash is a forward slash (“/”) placed at the end of a URL such as domain.com/ or domain.com/page/. But should you...
Read more >
Wrong repo url if you define a "Base URL" with a trailing slash
If you define a "Base URL" with a trailing slash in the server settings section like 'http://nexushost/nexus/' you cannot browse in the repo ......
Read more >
Redirect to URL with trailing slash doesn't occur in Websphere ...
Then I deployed the same application on WAS 8.5.5. Trying to access war module with the same URL localhost:9080/Foo/Bar (without trailing slash) and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found