redirect related questions...

Francis Daly francis at
Sat Jul 29 19:25:03 UTC 2017

On Fri, Jul 28, 2017 at 02:13:23PM +0300, ST wrote:

Hi there,

> server {
>  server_name; # and some more domains
>  return 301 $scheme://$request_uri;
> }
> server {
>  listen 80;
>  server_name;
>  ...
>  if ($http_user_agent !~ facebookexternalhit/1.1) {
>   return 301 https://$host$request_uri;
>  }
> }
> server {
>  listen 443 ssl;
>  server_name;
>  ...
> }

If that is your config, then the first server{} is used for http
connections for everything except; the second server is used
for http connections for only; and the third server is used
for all https connections.

> 1. redirects correctly to (via
>, but not - why?

https goes to server{} three; you have no redirection there.

> 2. neither nor redirect
> to (not even to - why?

https won't anyway, as per question 1.

http would, but only if the request actually gets to nginx. What do the
nginx logs say? Does resolve to an address on the nginx
server, as far as this client is concerned?

> How can I achieve that?

See why it fails right now.

If the request does not get to nginx, change things outside nginx so
that the request does get to nginx.

If the request does get to nginx, change things inside nginx so that it
does what you want.

That probably involves no change for http, but might involve a new server
for https which is the default server, and which does the redirect that
you want. Note that the client may choose not to accept the (redirect)
response if the certificate does not match whatever name they used to
connect to the server.

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list