# How to redirect http to https mender-api

**URL:** <https://hub.mender.io/t/how-to-redirect-http-to-https-mender-api/2215>\
**Category:** General Discussions\
**Created:** [July 22, 2020, 8:32am UTC](https://hub.mender.io/t/how-to-redirect-http-to-https-mender-api/2215 "2020-07-22T08:32:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![evk1206](https://avatars.discourse-cdn.com/v4/letter/e/9fc348/32.png) [@evk1206](https://hub.mender.io/u/evk1206)\
**Post date:** [July 22, 2020, 8:32am UTC](https://hub.mender.io/t/how-to-redirect-http-to-https-mender-api/2215/1 "2020-07-22T08:32:33Z")

</div>

Hello,

I have the self-hosted mender running on aws. eg URL: mender.myiotproject.link.

Using https works fine, [https://mender.myiotproject.link](https://mender.myiotproject.link).  
If I try to use http, [http://mender.myiotproject.link](http://mender.myiotproject.link), I expect the openresty to redirect it to https. But it’s not happening. I looked into the nginx config and see that the config to redirect is already present.

> <https://github.com/mendersoftware/mender-api-gateway-docker/blob/5f93dc149fcfa99dd0482efb1708a3f5459b7ac8/ssl.nginx.conf>

Should I need to configure something additional to redirect http to https for the mender URL?

Thanks & Regards,  
Vinoth

---

<div class="post-metadata">

**Author:** ![dellgreen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/dellgreen/32/85_2.png) [@dellgreen](https://hub.mender.io/u/dellgreen)\
**Post date:** [July 22, 2020, 9:01am UTC](https://hub.mender.io/t/how-to-redirect-http-to-https-mender-api/2215/2 "2020-07-22T09:01:11Z")

</div>

Can you give more details as to what redirect address your browser is being handed.

You might want to use curl/wget to get more verbose logging on what’s happening.

---

<div class="post-metadata">

**Author:** ![evk1206](https://avatars.discourse-cdn.com/v4/letter/e/9fc348/32.png) [@evk1206](https://hub.mender.io/u/evk1206)\
**Post date:** [August 17, 2020, 3:22pm UTC](https://hub.mender.io/t/how-to-redirect-http-to-https-mender-api/2215/3 "2020-08-17T15:22:58Z")

</div>

Hi,

There’s no setting on my browser.

**curl logs:**

curl [http://mender.iot-gateway-test.de](http://mender.iot-gateway-test.de) -v

- Rebuilt URL to: [http://mender.iot-gateway-test.de/](http://mender.iot-gateway-test.de/)
- Trying 52.59.217.\*…
- TCP\_NODELAY set
- Connected to [mender.iot-gateway-test.de](http://mender.iot-gateway-test.de) (52.59.217.\*) port 80 (#0)

> GET / HTTP/1.1  
> Host: [mender.iot-gateway-test.de](http://mender.iot-gateway-test.de)  
> User-Agent: curl/7.58.0  
> Accept: _/_

I expect the mender API Gateway to accept the http and redirect it to https. But it’s not working.

I am using the mender server 2.4

---

<div class="post-metadata">

**Author:** ![dellgreen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/dellgreen/32/85_2.png) [@dellgreen](https://hub.mender.io/u/dellgreen)\
**Post date:** [August 17, 2020, 4:06pm UTC](https://hub.mender.io/t/how-to-redirect-http-to-https-mender-api/2215/4 "2020-08-17T16:06:26Z")

</div>

It seems strange your client is not receiving the redirect header from the server

Its possible there has been a regression, as when I test 2.2 which i’m running i get a correct redirect header sent from the server (ignore the fact i’m running on port 9443)

```
 curl -v http://<myhost>:9443
 
 Trying <myhost>:9443...
* TCP_NODELAY set
* Connected to <myhost> (<myip>) port 9443 (#0)
> GET / HTTP/1.1
> Host: <myhost>:9443
> User-Agent: curl/7.68.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 301 Moved Permanently
< Server: openresty/1.13.6.2
< Date: Mon, 17 Aug 2020 15:56:46 GMT
< Content-Type: text/html
< Content-Length: 191
< Connection: close
< Location: https://<myhost>:9443/
< Strict-Transport-Security: max-age=63072000; includeSubdomains; preload
< X-Frame-Options: DENY
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store
< Pragma: no-cache
< 
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>openresty/1.13.6.2</center>
</body>
</html>
```

---

<div class="post-metadata">

**Author:** ![evk1206](https://avatars.discourse-cdn.com/v4/letter/e/9fc348/32.png) [@evk1206](https://hub.mender.io/u/evk1206)\
**Post date:** [August 18, 2020, 8:43am UTC](https://hub.mender.io/t/how-to-redirect-http-to-https-mender-api/2215/5 "2020-08-18T08:43:35Z")

</div>

This is working for me :

curl -v [http://myhost:443](http://myhost:443)

I want this to work :  
curl -v [http://myhost:80](http://myhost:80)

http is redirected to https

---

<div class="post-metadata">

**Author:** ![dellgreen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/dellgreen/32/85_2.png) [@dellgreen](https://hub.mender.io/u/dellgreen)\
**Post date:** [August 19, 2020, 12:07pm UTC](https://hub.mender.io/t/how-to-redirect-http-to-https-mender-api/2215/6 "2020-08-19T12:07:02Z")

</div>

I havent tried this, so dont know if it will work but maybe you can add an extra entry in your prod.yml file “80:443” for the api gateway.

> **[Compose file version 3 reference](https://docs.docker.com/compose/compose-file/#ports)**
>
> Reference and guidelines These topics describe version 3 of the Compose file format. This is the newest version. Compose and Docker compatibility matrix There are several versions of the Compose...

---

<div class="post-metadata">

**Author:** ![evk1206](https://avatars.discourse-cdn.com/v4/letter/e/9fc348/32.png) [@evk1206](https://hub.mender.io/u/evk1206)\
**Post date:** [August 19, 2020, 4:25pm UTC](https://hub.mender.io/t/how-to-redirect-http-to-https-mender-api/2215/7 "2020-08-19T16:25:16Z")

</div>

Setting “80:80” is working.

---

<div class="post-metadata">

**Author:** ![dellgreen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/dellgreen/32/85_2.png) [@dellgreen](https://hub.mender.io/u/dellgreen)\
**Post date:** [August 19, 2020, 6:49pm UTC](https://hub.mender.io/t/how-to-redirect-http-to-https-mender-api/2215/8 "2020-08-19T18:49:27Z")

</div>

just to clarify, you now have it working how you want it?
