I have been handed over a redeployment of an app allready deployed on a Windows server, where both the python backend, postgress db and frontend is on the same server. I have asked to seperate it and to put it on linux dockers. The consultant that originally made is no longer availiable, so I'm not perfectly sure what is crucial and what is not.

On my own ubuntu pc I'm developing this using --network=host. I have setup the postgress and the python backend with waitress listening to localhost:7000 and now I need to make the nginx docker.

The deployment instructions for the windows server related to the nginx config file are:

After editing the config on the remote machine, you can reload it with psexec -w C:\tools\nginx -s nginx -s reload. (nginx is saved in C:\tools\nginx)

server_names_hash_bucket_size 64;

proxy_buffering on;
proxy_buffers 24 4k;
proxy_busy_buffers_size 32k;

proxy_set_header Host $host;
proxy_http_version 1.1;

gzip on;
gzip_proxied any;
gzip_min_length 1000;

# Test setup
server {
    listen 80;
    server_name test.xxx.yyy.com localhost;
    root C:/www/html-dev;

    error_log C:/www/error-dev.log debug;

    index index.html;
    try_files $uri $uri/ /index.html;

    charset utf-8;

    location /api/ {
        proxy_pass http://localhost:7000/;

    location /nginx-status {

After seeing this nginx setup my current dockerfile is something like this:

FROM nginx
COPY html /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf

Any surgestions for a suitiable nginx.conf for this setup or is there something I have missed? In general almost any advise will be appreciated(I'm a noob).


According to the posted nginx configuration, you mainly wan to do three things:

  • Listen on test.xxx.yyy.com:80
  • Serve files vom C:/www/html-dev directly (I'm assuming this is static content like img/css/js)
  • Expect /api/, this simply got proxied to http://localhost:7000 (Should be the app server)

You can use this config, but this requires some configuration on the Docker side. The nginx container needs access to the static contend, which is located in C:/www/html-dev on the old Win server. It's possible to include this in the image (Dockerfile)

COPY html-dev /usr/share/nginx/html

or mount it as a Volume at runtime like this in docker-compose

version: "2.4"
    image: nginx:1.16-alpine
      - ./html-dev:/usr/share/nginx/html
    # Access nginx on port 80 of the host (if already taken, change it)
      - 80:80

The volume approach is faster, especially during development when the folder contains a lot of files.

In general, I'd recommend you the usage of docker-compose here. It makes the handling of multiple containers easily. This is what you need here, because the Docker approach would require one container per application. So you don't put your Python app in the nginx container.

Since nginx can't directly talk to a Python backend, you need WSGI. Without it this only works using Pythons development server. But according to the documentation, this is not production ready and shouldn't be used outside developing. Your config looks like that the backend is this kind of dev server (or you have something betweem them that is not shown).

I'd recommend to resolve this properly using WSGI, for example you could use [uWSGI](http://flask.pocoo.org/docs/1.0/deploying/uwsgi/) for this. Find well documented Docker images here: https://github.com/tiangolo/uwsgi-nginx-flask-docker

In short, this would result in another Container that you'll upstream your nginx to. localhost needs to be replaced by this service name. For example, if the service is called uwsgi in docker-compose.yml, use uwsgi with the corresponding host instead of localhost. This is possible since docker-compose itself creates a virtual network between it's containers per default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.