Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running application on subpath #31

Open
bandaangosta opened this issue Jun 19, 2020 · 0 comments
Open

Running application on subpath #31

bandaangosta opened this issue Jun 19, 2020 · 0 comments

Comments

@bandaangosta
Copy link

Hello.
I am trying to migrate a web application from using the tiangolo/uwsgi-nginx-flask image to this one, based on Meinheld, Gunicorn and Flask.
My application runs behind a reverse proxy implemented with Traefik, and is mounted on a subpath. For example, on "/demo".
I have a cookiecutter template that easily implements most of this setup, except for the Traefik bits, which I add on deployment using docker-compose and a docker-compose.yml file like this:

version: '3'

services:
  # The reverse proxy service (Træfik)
  reverse-proxy:
    image: traefik  # The official Traefik docker image
    command: --api --docker   # Enables the web UI and tells Træfik to listen to docker
    restart: always
    ports:
      - "80:80"      # The HTTP port
      - "8080:8080"  # The Web UI (enabled by --api)
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock  # So that Traefik can listen to the Docker events

  myapp:
    build:
      context: ./myapp/
      dockerfile: Dockerfile.nginx-uwsgi # just change to Dockerfile.meinheld-gunicorn to use this image as base
    labels:
      - "traefik.frontend.rule=PathPrefix:/demo"
      - "traefik.frontend.priority=1"
    depends_on:
      - reverse-proxy

When using nginx and uwgsi, I need to add a couple of lines to the uwsgi.ini config file, following hints from Flask uwsgi docs:

[uwsgi]
; Uncomment following lines if not mounting the application on root "/" (see http://flask.pocoo.org/docs/1.0/deploying/uwsgi/)
manage-script-name   <--- ADDED FOR MOUNTING ON SUBPATH /demo
mount = /demo=myapp:app   <--- ADDED FOR MOUNTING ON SUBPATH /demo
module = myapp
callable = app
uid = uwsgi
gid = uwsgi

How can I achieve the same thing when using this Meinheld + Gunicorn image?

Gunicorn docs briefly mentions that SCRIPT_NAME can be set in the environment for Gunicorn to pick up. meinheld-gunicorn-flask image does not provide SCRIPT_NAME as an environment variable to set (I tried it anyway), so the next thing I tried is adding this setting in the gunicorn_conf.py file. Following this issue comment for format, I added the following to gunicorn_conf.py (tried with and without the slash):

# Environment variables
raw_env = [
    "SCRIPT_NAME=/demo"
    ]

Not working.
Can you help me with this one? Is this a problem with the image or am I just trying to implement this subpath feature the wrong way here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants