Problems with redirects

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems with redirects

Danny Horne
Hi all,

I've been struggling to get redirects working the way I'd like,
basically I want -

http://trisect.uk > https://trisect.uk
http://site1.trisect.uk > https://site1.trisect.uk
http://site2.trisect.uk > https://site2.trisect.uk
etc....

This is the server block doing the redirects -

server {
         listen *:80;
         listen [::]:80;

         server_name trisect.uk *.trisect.uk;

         return 301 https://$server_name$request_uri;
}

I have a wildcard Let's Encrypt certificate and am using NginX 1.14.2

Hope someone can help, thanks for looking

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Problems with redirects

j94305
Hi Danny,

  two comments:

1) Don't forget about $is_args$args to also pass any arguments supplied with
the URL.

2) You cannot redirect requests with a request body, most importantly POST
and PUT, so your rule is only applicable for GET/HEAD requests.

I have no idea what you are really struggling with as you don't mention the
actual challenge.

Regarding your server block:

- "listen 80 default_server;" is sufficient.

- You can specify server names, but your intention is to forward everything,
so you may as well omit it or write a dummy such as "server_name _;"

- You may want to add a different redirection if the request method is not
GET (or HEAD), so users will end up on the home page or somewhere else
meaningful and not have to face a funny error message the won't understand,
because a POST/PUT request did not specify a body.

Regarding the https service:

- If you use one IP address to serve multiple domains, get a SAN certificate
with all domain names added. This way, you can avoid using SNI.

Cheers,

--j.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,285882,285884#msg-285884

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Problems with redirects

Danny Horne
On 15/10/2019 13:56, j94305 wrote:
> I have no idea what you are really struggling with as you don't mention the
> actual challenge.
>
The problem is, whatever URL I put in the browser, it redirects to
https://trisect.uk
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

RE: Problems with redirects

Reinis Rozitis
> The problem is, whatever URL I put in the browser, it redirects to
> https://trisect.uk _______________________________________________

> server_name trisect.uk *.trisect.uk;
> return 301 https://$server_name$request_uri; }

For that I don't think you can use $server_name here because it will always be the first one picked no matter if the client passes site1.trisect.uk in Host header.

Try with return 301 https://$host$request_uri;

rr





_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Problems with redirects

Danny Horne
On 15/10/2019 14:08, Reinis Rozitis wrote:
>> The problem is, whatever URL I put in the browser, it redirects to
>> https://trisect.uk _______________________________________________
>> server_name trisect.uk *.trisect.uk;
>> return 301 https://$server_name$request_uri; }
> For that I don't think you can use $server_name here because it will always be the first one picked no matter if the client passes site1.trisect.uk in Host header.
>
> Try with return 301 https://$host$request_uri;
>
> rr

Ok, I think I'm there with the following server block, I think the main
problem was that I'd shot myself in the foot by using 301 redirects,
which Chrome was caching, testing with another browser showed everything
working as desired.  Clearing the Chrome redirect cache has (I think)
fixed it.

server {
         listen *:80;
         listen [::]:80;

         server_name trisect.uk *.trisect.uk;

         return 301 https:/$host$request_uri;
}

Thanks for all replies

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx