I have a simple Flask app running on Windows 10 using nginx, uwsgi, and a docker-compose.yml file. My Dockerfile is using this container image: tiangolo/uwsgi-nginx-flask:python3.11.
I'm trying to restrict it to running on a specific custom domain on my local machine, site1.test. It seems to run on any custom domains I make.
In my docker-compose.yml file I have the following:
version: "3.7"
services:
# define our services
flask:
build: ./flask
container_name: flask
restart: always
environment:
- APP_NAME=MyFlaskApp
VIRTUAL_HOST: site1.test
VIRTUAL_PORT: 3000
expose:
- 8080
volumes:
- ./log/uwsgi:/var/log/uwsgi
nginx:
build: ./nginx
container_name: nginx
restart: always
ports:
- "80:80"
volumes:
- ./log/nginx:/var/log/nginx
nginx-proxy:
image: jwilder/nginx-proxy
ports:
- 80:80
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
The last service, nginx-proxy, was added today along with the VIRTUAL_HOST and VIRTUAL_PORT variables in the flask service's environment in an effort to restrict the app running ON AND ONLY ON site1.test locally; it didn't work. I also added the following to my hosts file:
127.0.0.1 site1.test
My nginx.conf file looks like this:
server {
listen 80;
location / {
include uwsgi_params;
uwsgi_pass flask:8080;
}
}
My app loads when I type site1.test in my browser. If I keep the host file the same and change the flask service's enironment VIRTUAL_HOST to something different, like site25.test, my app still loads on site1.test. I'm trying to restrict my app to a particular custom domain.
What am I doing wrong?
In addition to adding what I did in the docker-compose.yml file, I had a block in nginx.conf that tried using a server site1.test, and also server_name site1.test when that didn't work. I also tried adding both
127.0.0.1 site1.test
127.0.0.1 site25.test
to my hosts file, in hopes that with more than a single custom domain listed, it might only work on one. However, then my app just loads on both domains.