Redirect from HTTP to HTTPS does not work

This is my configuration:

server {
listen 80;
server_name shell.*;
return 301 https://$server_name$request_uri;
}

server {
listen 443 ssl;
server_name shell.*;

location / {
proxy_pass http://192.168.0.16:4200;
}
}

I am using a Dynamic DNS Service to access NGINX running on my Raspberry
Pi.

The configuration perfectly works for https://shell.raspi.dyndns.com but
not
for http://shell.raspi.dyndns.com (message: The requested URL could not
be
retrieved. The system returned: Operation timed out.).

Any idea what the problem could be and how to fix it?

Regards,
Steffen

Posted at Nginx Forum:

On Tue, Aug 11, 2015 at 02:53:21AM -0400, StSch wrote:

Hi there,

This is my configuration:

server {
listen 80;
server_name shell.*;
return 301 https://$server_name$request_uri;
}

When you request “http://shell.example.com/uri”, this will redirect to
https://shell.*/uri”, which is probably not what you want.

Use (for example) $host instead of $server_name.

Or (possibly better) use shell.raspi.dyndns.com instead of $server_name.

Any idea what the problem could be and how to fix it?

Use “curl -i” to make the http request. See the response.

f

Francis D. [email protected]

Use “curl -i” to make the http request. See the response.

Use (for example) $host instead of $server_name.

Thank you very much for your immediate response and sorry for my late
reply.
“curl -i” was very useful and using “$host” instead of “$server_name”
indeed
solved my problem. Thank you very much for your help.

Greetings from South-Germany,
Steffen

Posted at Nginx Forum: