https://github.com/gh640/python-https-servers
Examples of an https server for development. Works on Python 3.
https://github.com/gh640/python-https-servers
https python self-signed-certificate
Last synced: 7 months ago
JSON representation
Examples of an https server for development. Works on Python 3.
- Host: GitHub
- URL: https://github.com/gh640/python-https-servers
- Owner: gh640
- Created: 2021-03-07T05:32:16.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-14T13:09:58.000Z (over 2 years ago)
- Last Synced: 2024-05-02T01:12:01.952Z (over 1 year ago)
- Topics: https, python, self-signed-certificate
- Language: Python
- Homepage:
- Size: 31.3 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Python https servers
Examples of an https server for development. **Never use them for production.**
## Samples
There're 3 samples.
1. Python standard libraries
2. Gunicorn
3. Gunicorn + Flask## Usage
### Preparation
Generate a self-signed certificate and name it `localhost.pem`.
```bash
cd python-https-servers/
openssl req -x509 -new -days 365 -nodes \
-keyout localhost.pem \
-out localhost.pem \
-subj "/CN=localhost"
``````text
Generating a 2048 bit RSA private key
.....................................................................................................................................+++
........+++
writing new private key to 'localhost.pem'
-----
```### 1. Python standard libraries
Just execute `run-python.sh`.
```bash
./run-python.sh
```### 2. Gunicorn
Install the required packages with [Poetry](https://python-poetry.org/) or `pip`.
```bash
poetry install
# or
python3 -m pip install gunicorn
```Then execute `run-gunicorn.sh`.
```bash
./run-gunicorn.sh
```### 3. Gunicorn + Flask
Install the required packages with Poetry or `pip`.
```bash
poetry install
# or
python3 -m pip install gunicorn Flask
```Then execute `run-gunicorn-flask.sh`.
```bash
./run-gunicorn-flask.sh
```You can view the sample html file on your browser with `https://localhost`.
```bash
open https://localhost
```## Files
```text
├── README.md: This file
├── gunicorn.conf.py: Config file for Gunicorn
├── htdocs: Served directory
├── localhost.pem: Self-signed certificate (You need to create this.)
├── poetry.lock: Poetry lock file (You don't need this if you don't use Poetry)
├── pyproject.toml: Poetry project file (You don't need this if you don't use Poetry)
├── run-gunicorn-flask.sh: Script to run `with_gunicorn_flask/app.py`
├── run-gunicorn.sh: Script to run `with_gunicorn/app.py`
├── run-python.sh: Script to run `with_python/server.py`
├── with_gunicorn
│ └── app.py: Sample with Gunicorn
├── with_gunicorn_flask
│ └── app.py: Sample with Gunicorn and Flask
└── with_python
└── server.py: Sample with Python standard libraries
```## Reference
- [`http.server` HTTP servers — Python 3 documentation](https://docs.python.org/3/library/http.server.html)
- [`ssl` TLS/SSL wrapper for socket objects — Python 3 documentation](https://docs.python.org/3/library/ssl.html)
- [Creating an HTTPS server in Python · Martin Pitt](https://piware.de/2011/01/creating-an-https-server-in-python/)
- [simple-https-server.py · GitHub](https://gist.github.com/dergachev/7028596)
- [Simple Python HTTP(S) Server Example · AnvilEight Blog](https://blog.anvileight.com/posts/simple-python-http-server/)