# Docker VPS work with HTTP but not with HTTPS

**URL:** <https://forums.docker.com/t/docker-vps-work-with-http-but-not-with-https/139107>\
**Category:** General\
**Tags:** docker\
**Created:** [December 31, 2023, 8:46am UTC](https://forums.docker.com/t/docker-vps-work-with-http-but-not-with-https/139107 "2023-12-31T08:46:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kabrice](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/kabrice/32/44403_2.png) [@kabrice](https://forums.docker.com/u/kabrice)\
**Post date:** [December 31, 2023, 8:46am UTC](https://forums.docker.com/t/docker-vps-work-with-http-but-not-with-https/139107/1 "2023-12-31T08:46:48Z")

</div>

I am trying to host my Flask Rest API from Docker container within a VPS (apache). Its working fine with `http` but not working with `https`.

Dockerfile

```auto
FROM python:3.11
# Virtual envs not needed inside container
WORKDIR /app
COPY ./requirements.txt /app/requirements.txt
COPY . /app
RUN python3 -m pip install -r /app/requirements.txt

EXPOSE 5000
CMD ["flask", "--app=app", "run", "--host=0.0.0.0"]

```

running `$ docker run --rm -it -p 8080:5000 myapp:latest` allow me to run `http://myapphostwebsite.com:8080/user/12345` on Postman. I could then retrieve data but when using `https://myapphostwebsite.com:8080/user/12345` , I got this Postman error :

```auto
Error: write EPROTO 5543930632:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:../../../../src/third_party/boringssl/src/ssl/tls_record.cc:242:

```

And the Docker Log gives this

```auto
code 400, message Bad request version ('À\x13À') \x16\x03\x01\x00ü\x01\x00\x00ø\x...

```

I don’t know what to do. How to access my Docker container outside with https?

PS : I used Certbot to setup SSL on my VPS

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [December 31, 2023, 11:30am UTC](https://forums.docker.com/t/docker-vps-work-with-http-but-not-with-https/139107/2 "2023-12-31T11:30:48Z")

</div>

Your flask looks like it is configured to expect HTTP conection, not HTTPS. Please, share why you think it should work. How did you configured flask to expect HTTPS on the port?

---

<div class="post-metadata">

**Author:** ![kabrice](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/kabrice/32/44403_2.png) [@kabrice](https://forums.docker.com/u/kabrice)\
**Post date:** [December 31, 2023, 11:40am UTC](https://forums.docker.com/t/docker-vps-work-with-http-but-not-with-https/139107/3 "2023-12-31T11:40:16Z")

</div>

Here is the main file (containing the config) of my Flask app, it’s very basic :  
app.py

```auto
from flask import Flask, request, jsonify, json
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.event import listens_for
from flaskext.mysql import MySQL
from flask_cors import CORS
from dataclasses import dataclass
from sqlalchemy import text
from urllib.parse import quote

app = Flask( __name__ )

db = SQLAlchemy()

mysql =MySQL()

@dataclass
class User(db.Model):

    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True)
    firstname = db.Column(db.String(46), nullable=False)#1
    lastname = db.Column(db.String(46), nullable=False)#1
    

    def __init__ (self, firstname, lastname):
        self.firstname = firstname
        self.lastname = lastname

    def as_dict(self):
        excluded_fields = ['id']
        return {field.name:getattr(self, field.name) for field in self. __table__.c if field.name not in excluded_fields}

@dataclass
class User(db.Model):

    __tablename__ = 'user'
    __table_args__ = {'extend_existing': True} 

    id = db.Column(db.Integer, primary_key=True)
    firstname = db.Column(db.String(46), nullable=False)#1
    lastname = db.Column(db.String(46), nullable=False)#1

    def __init__ (self, firstname, lastname):
        self.firstname = firstname
        self.lastname = lastname

    def as_dict(self):
        excluded_fields = ['id']
        return {field.name:getattr(self, field.name) for field in self. __table__.c if field.name not in excluded_fields}

app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://username:pwd@127.0.0.1/test'

db.init_app(app)
with app.app_context():
    db.create_all()

@app.route('/users', methods=['GET'])
def get_user():
    users = User.query.all()
    return jsonify(users)

@app.route('/user/<firstname>', methods=['GET'])
def user_byfirstname(firstname):
    user = User.query.filter_by(firstname = firstname).first()
    return jsonify(user.as_dict())

if __name__ == ' __main__':
   app.run(debug=True)

```

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [December 31, 2023, 2:55pm UTC](https://forums.docker.com/t/docker-vps-work-with-http-but-not-with-https/139107/4 "2023-12-31T14:55:36Z")

</div>

I don’t see anything SSL related in the shared code. Please, point out which line is responsible for that.

I’m also going to move the topic out of the Docker Hub category as it has nothing to do with Docker Hub.

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/bluepuma77/32/32688_2.png) [@bluepuma77](https://forums.docker.com/u/bluepuma77)\
**Post date:** [December 31, 2023, 5:26pm UTC](https://forums.docker.com/t/docker-vps-work-with-http-but-not-with-https/139107/5 "2023-12-31T17:26:18Z")

</div>

Flask probably doesn’t know very much about TLS/SSL. You either need to buy a cert or use something like LetsEncrypt to create a free one.

Usually a reverse proxy is used in front of applications to manage and terminate TLS, check nginx-proxy and companion ([link](https://github.com/nginx-proxy/nginx-proxy)) or simple Traefik example ([link](https://github.com/bluepuma77/traefik-best-practice/tree/main/docker-traefik-dashboard-letsencrypt)).

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [December 31, 2023, 5:31pm UTC](https://forums.docker.com/t/docker-vps-work-with-http-but-not-with-https/139107/6 "2023-12-31T17:31:12Z")

</div>

> [@bluepuma77](#):
>
> buy a cert or use something like LetsEncrypt to create a free one.

just to point out that it is the case 🙂

> [@kabrice](#):
>
> PS : I used Certbot to setup SSL on my VPS

But it is not clear how that was configured to be used. If flask can handle it, I would use that unless I need to run other containers too. Then I would definitely use Traefik.

---

<div class="post-metadata">

**Author:** ![kabrice](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/kabrice/32/44403_2.png) [@kabrice](https://forums.docker.com/u/kabrice)\
**Post date:** [January 7, 2024, 10:46pm UTC](https://forums.docker.com/t/docker-vps-work-with-http-but-not-with-https/139107/7 "2024-01-07T22:46:40Z")

</div>

setting up ssl into my Flask app solved my problem. Thx everyone
