Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unwanted redirects to localhost #392

Closed
Northernside opened this issue Dec 1, 2023 · 27 comments
Closed

Unwanted redirects to localhost #392

Northernside opened this issue Dec 1, 2023 · 27 comments

Comments

@Northernside
Copy link

I've tried to setup Accent and I think I got it somewhat right (can't know because your docs either aren't updated or just barely finished.. or both? it's just not user/developer friendly, that's something I can tell), I believe.
The problem now is, that I've setup an A record for translate.ebio.gg which points towards my server and the server is a Nginx reverse proxy. This is my configuration:
image

Yet, when accessing https://translate.ebio.gg, it just redirects the browser to localhost. Is there any reason why and any way for fixing this?

Accesing the localhost:4000 web server on the same machine seems to actually return data.
image

This is the Docker log:
image

@simonprev
Copy link
Member

Hello! What’s your CANONICAL_URL in your env var? All the necessary config are documented here: https://github.com/mirego/accent?tab=readme-ov-file#production-setup

From what I can tell you will need CANONICAL_URL=https://translate.ebio.gg

@Northernside
Copy link
Author

Hello there,
my CANONICAL_URL is set to https://translate.ebio.gg. This is my entire environment variables configuration:
image

Are all of the ones from https://github.com/mirego/accent?tab=readme-ov-file#production-setup fully required?

@simonprev
Copy link
Member

I think your env var are not loaded correctly since the log should show the full URL here:

[info] Running Accent.Endpoint with Bandit 1.1.0 at 0.0.0.0:4000 (http)
[info] Access Accent.Endpoint at https://afdh9f20-asdoh.ngrok.io

If you are statring it with docker compose, the environment is not read from the .env file, it is declared directly in the yaml file. This could be improved in the documentation. A PR is welcome!

@RappyTV
Copy link

RappyTV commented Dec 1, 2023

Maybe also dont put https:// before the canonical url. That broke my instance

@Northernside
Copy link
Author

I think your env var are not loaded correctly since the log should show the full URL here:

[info] Running Accent.Endpoint with Bandit 1.1.0 at 0.0.0.0:4000 (http)
[info] Access Accent.Endpoint at https://afdh9f20-asdoh.ngrok.io

If you are statring it with docker compose, the environment is not read from the .env file, it is declared directly in the yaml file. This could be improved in the documentation. A PR is welcome!

Am I doing something wrong again or not? I tried to port the vars from .env to the docker-compose.yml.

image image

@RappyTV
Copy link

RappyTV commented Dec 1, 2023

@Northernside you misspellt CANONICAL xd

@Northernside
Copy link
Author

oh my fucking god
...
idk what to say
😭

@Northernside
Copy link
Author

Northernside commented Dec 1, 2023

image

okay well, it does show me the correct url now, but it still redirects to localhost :p

@RappyTV
Copy link

RappyTV commented Dec 1, 2023

i don't think that this is the problem but it will solve a problem later. try to remove the https:// in the canonical url. that solved the problem for me

@Northernside
Copy link
Author

Well, now it shows localhost:4000 again.
image

Strangely enough, I can access the website through the direct ip + port but not when using a domain proxied through Cloudflare and then through Nginx.

@RappyTV
Copy link

RappyTV commented Dec 1, 2023

Yes it shows that on my machine too

@RappyTV
Copy link

RappyTV commented Dec 1, 2023

But it works

@simonprev
Copy link
Member

By removing the https:// the canonical is invalid so it does not enforce a URL 😄 That’s why it works.

@RappyTV
Copy link

RappyTV commented Dec 1, 2023

oh lmao. well if I didn't remove the https:// I would just get a too much redirects error

@RappyTV
Copy link

RappyTV commented Dec 1, 2023

turns out http:// works

@remi
Copy link
Member

remi commented Dec 1, 2023

Yes indeed, because SSL is enforced if the canonical URI is using https.

https://github.com/mirego/accent/blob/master/config/runtime.exs#L23

@remi
Copy link
Member

remi commented Dec 1, 2023

If you’re using nginx to handle the TLS stuff, the Elixir application should not be handling it too.

@remi
Copy link
Member

remi commented Dec 1, 2023

However, if nginx is handling the TLS termination and passing the X-Forwarded-Proto to the Elixir application, CANONICAL_URL=https://… should work.

https://github.com/mirego/accent/blob/master/lib/accent/endpoint.ex#L50

@Northernside
Copy link
Author

This is my Cloudflare:
image

it passes translate.ebio.gg to server X and server X is a Nginx server which then passes it to 127.0.0.1:4000, as seen here:
image

127.0.0.1:4000 is Accent and it's configuration is this:
image

cURL'ing both http and https:
image

Maybe this clarifies a bit more of my current issue/situation. Do you know any way on how I can prevent it from redirecting to localhost?

Changing the CANONICAL_URL from https://translate.ebio.gg to http://translate.ebio.gg does not change anything in terms of behaviour, as seen here again:
image

Also explicitly setting FORCE_SSL to false has no effect on this behaviour.

@RappyTV
Copy link

RappyTV commented Dec 1, 2023

then you also have to change the https:// to http:// in the canonical url as remi said

@Northernside
Copy link
Author

then you also have to change the https:// to http:// in the canonical url as remi said

image Well.. 👀

@RappyTV
Copy link

RappyTV commented Dec 1, 2023

ah i'm dumb and i can't read

@Northernside
Copy link
Author

dont worry!

@simonprev
Copy link
Member

Yeah FORCE_SSL is documented but not used in the codebase, that’s my bad 😄

@Northernside
Copy link
Author

However, if nginx is handling the TLS termination and passing the X-Forwarded-Proto to the Elixir application, CANONICAL_URL=https://… should work.

https://github.com/mirego/accent/blob/master/lib/accent/endpoint.ex#L50

image

Tried that, nothing changed 👀

@Northernside
Copy link
Author

Oh, funny thing: if I access https://translate.ebio.gg/ it returns me to https://localhost but if I access https://translate.ebio.gg/? (or any other query related input) it returns me to https://translate.ebio.gg/ AND serves the proper content. What? 😭

@Northernside
Copy link
Author

Oh oops nevermind, it seems like it was just a silly cache on my side!

Thank you for all your help ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants