-
Notifications
You must be signed in to change notification settings - Fork 3k
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
How do I make nginx-proxy redirect to www. and enforce https/ssl? #958
Comments
Not a single hint? |
I think you are more likely to get a response if you include something in the body :) There is a section on enforcing HTTPS/SSL in the README - I'll assume you are running another
Now requests for |
Thanks, actually thats what I did eventually, but on the nginx-proxy, by including a vhost file. However 1. I think this should be done upfront at the proxy, so that the request is redirected right there and does not hast to go all the way through ... Thanks though |
Redirecting to www is definitely a common thing - I do it as well. Maybe there is a graceful way for us to do it in |
For the https redirect from example.com to www.example.com, here I how I got it done:
server {
It is working, however, this is still a workaround as I have domain hardcoding in the extra.conf. |
@xczheng is this config still working for you? Or you found something better? With the current versions of I've been messing a long time with this. User @witten suggests to use a separate redirect container. Seems like overkill, but at least it works. https://hub.docker.com/r/morbz/docker-web-redirect/ |
I am running nginx-proxy for internal services. I wanted to redirect all short names to their corresponding fully qualified names. e.g. http://git/ -> https://git.internal.example.com/ I borrowed from @xczheng's idea, but instead of adding a new config file I modified the
Then I removed all the short names from the docker-compose.yml VIRTUAL_HOST. |
Thanks @xczheng your instructions worked perfect for my nonwww to www redirect, and the rest of my subdomains route as expected too. |
I'm very confused about how this works across containers: location /old/URL { The wrong container is answering. When /old/URL is visited, it is via the domain need.to/old/URL, so the nginx-proxy talks to need.to's container, but the newURL.need.to needs to be the container nginx-proxy talks to... This nginx config was placed in the correct vhost.d/VIRTUAL_HOST filename. Do I need to use internal URLs or some docker-magic? Thanks a lot... Stuck! |
OK, I figured it out using the following: However... I also needed to use "HTTPS_METHOD=noredirect" in the container's env... And this has ended up causing other issues... Is there no way in this configuration to have no SSL redirect for a single regex / specific URL? This one proxy_pass has caused the website to required the noredirect setting for its entire domain! |
This seems like the solution: Anyone know which .pems to specify, though? And which files in nginx-proxy's certs mount to use as the .key file (as specify in the above nginx doc)? EDIT: Figured it out: it is the per-VHOST fullchain.pem (for the cert) and key.pem (for the cert's key). |
I've consolidated & clarified my question here: #1340 |
@propheth were you able to get it working? I've been attempting to solve this issue without success |
@propheth great to hear that it works. I'm using https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion which seems to be adding some more complexity. I will try again tomorrow from scratch. Thanks! |
@propheth I think your solution only works when redirecting from an http site. According to nginx docs, when no Also, I submitted #1369 to address this issue. If you want to take a look and use it before it gets merged, all you need is the updated nginx.tmpl. See #1369 for usage details. Cheers, hope it helps! |
@dannycarrera the solution should work for both. The standard Before applying the solution, your setup should already be redirecting from The upstream |
Hi @dannycarrera, Could you finally achieve the redirect? |
@d4n1b Yes, I made a PR #1369 for the changes to make it work seamlessly. They haven't been merged in yet, but I created a fork you can use if you don't want to wait. https://hub.docker.com/r/dannycarrera/nginx-proxy |
Thanks @dannycarrera! - I'll use that one in the meantime, as it looks like it's going to take a while to be merged. |
No description provided.
The text was updated successfully, but these errors were encountered: