# Redirect from HTTP to HTTPS does not work

**URL:** <https://www.ruby-forum.com/t/redirect-from-http-to-https-does-not-work/242965>\
**Category:** NGINX\
**Created:** [August 11, 2015, 8:53am UTC](https://www.ruby-forum.com/t/redirect-from-http-to-https-does-not-work/242965 "2015-08-11T08:53:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [August 11, 2015, 8:53am UTC](https://www.ruby-forum.com/t/redirect-from-http-to-https-does-not-work/242965/1 "2015-08-11T08:53:53Z")

</div>

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](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](https://shell.raspi.dyndns.com) but  
not  
for [http://shell.raspi.dyndns.com](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:

> **[Redirect from HTTP to HTTPS does not work](https://forum.nginx.org/read.php?2,260913,260913#msg-260913)**
>
> 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

---

<div class="post-metadata">

**Author:** ![StSch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ebca7d/32.png) [@StSch](https://www.ruby-forum.com/u/StSch)\
**Post date:** [August 11, 2015, 9:36am UTC](https://www.ruby-forum.com/t/redirect-from-http-to-https-does-not-work/242965/2 "2015-08-11T09:36:32Z")

</div>

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](http://shell.example.com/uri)”, this will redirect to  
“[https://shell](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](http://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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![StSch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ebca7d/32.png) [@StSch](https://www.ruby-forum.com/u/StSch)\
**Post date:** [September 8, 2015, 2:01pm UTC](https://www.ruby-forum.com/t/redirect-from-http-to-https-does-not-work/242965/3 "2015-09-08T14:01:54Z")

</div>

> 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:  
[http://forum.nginx.org/read.php?2,260913,261506#msg-261506](http://forum.nginx.org/read.php?2,260913,261506#msg-261506)
