Setup a pair of Nginx proxy/web server to handle CORS process.
This document is based on: tiangolo/uwsgi-nginx-flask.
Also, refer to this one: Nginx configuration for CORS-enabled HTTPS proxy with origin white-list defined by a simple regex
- debian:stretch
- Nginx
- Python3 (with python-extras)
- uWSGI
- app (Flask sample app)
.
├── Dockerfile
├── README.md
├── app
│ ├── main.py
│ ├── static
│ │ └── index.html
│ └── uwsgi.ini (application uwsgi ini file)
├── entrypoint.sh (will generate nginx.conf in conf.d)
├── nginx
│ ├── conf.d
│ │ └── proxy.conf (cors handling and to forward request to port 8080)
│ └── nginx.conf
├── supervisor
│ └── supervisord.conf (run both uwsgi and nginx)
├── update.sh (easy of update container files)
└── uwsgi
└── uwsgi.ini (update to /etc/uwsgi in container)
docker build -t cors-proxy .
In host command windows:
docker run -d --name cors-proxy cors-proxy
Browse link "localhost" or "localhost:8080", it will show:
Docker Running ! Hello World from static HTML
Browse link "localhost/hello" or "localhost:8080/hello", it will show:
Hello World from Flask
It can open another host comand windows and run the below command to check log:
docker logs -f cors
In addition, it can run the bash of container to do what you want, like install additional packages, etc.
docker exec -i -t cors-proxy /bin/bash
root@c19867aff7dc:/app# ls
__pycache__ main.py static uwsgi.ini
root@c19867aff7dc:/app#
docker run -d --name cors-proxy cors-proxy
or
# redirect aceess from localhost:8080 to container:80
docker run -d --name cors-proxy -p 8080:80 cors-proxy
docker start cors
docker restart cors
docker stop cors
# exec bash in container
sudo docker exec -i -t cors-proxy /bin/bash
# show Nginx logs
docker logs -f cors
# docker cp <containerId>:/file/path/within/container /host/path/target
docker cp nginxpx:/etc/nginx/nginx.conf .
docker rm -f cors
# remove all containers
docker rm -f $(docker ps -aq)
docker rmi