Last active
December 25, 2020 06:08
-
-
Save jackiect/b3aab73ee361b76eaa2fcf2f9de383f3 to your computer and use it in GitHub Desktop.
Reverse proxy in Traefik with subdirectories.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
app = Flask(__name__) | |
@app.route('/') | |
def hello_world(): | |
return 'Hello, World!' | |
@app.route('/flask/') | |
@app.route('/flask/<int:post_id>') | |
def post(post_id=0): | |
print(post_id) | |
return 'Hello, Flask!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3" | |
services: | |
client: | |
image: alpine | |
command: tail -f /dev/null | |
flask: | |
build: . | |
ports: | |
- 9080-9089:8080 | |
scale: 2 | |
labels: | |
- "traefik.enable=true" | |
- "traefik.http.routers.flask.entrypoints=front" | |
- "traefik.http.routers.flask.rule=PathPrefix(`/flask{regex:$$|/.*}`)" | |
- "traefik.http.routers.flask.middlewares=flask-stripprefix" | |
- "traefik.http.middlewares.flask-stripprefix.stripprefix.prefixes=/" | |
networks: | |
- traefik01 | |
- traefik02 | |
httpd: | |
image: httpd:2.4.41-alpine | |
expose: | |
- 80 | |
scale: 2 | |
labels: | |
- "traefik.enable=true" | |
- "traefik.http.routers.httpd.entrypoints=front" | |
- "traefik.http.routers.httpd.rule=PathPrefix(`/httpd{regex:$$|/.*}`)" | |
- "traefik.http.routers.httpd.middlewares=httpd-stripprefix" | |
- "traefik.http.middlewares.httpd-stripprefix.stripprefix.prefixes=/httpd" | |
networks: | |
- traefik01 | |
- traefik02 | |
networks: | |
traefik01: | |
external: true | |
traefik02: | |
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3" | |
services: | |
simple_http: | |
image: python:3.7.8-alpine | |
working_dir: /data | |
command: python -m http.server 5000 | |
ports: | |
- 5000-5009:5000 | |
scale: 2 | |
labels: | |
- "traefik.enable=true" | |
- "traefik.http.routers.simple_http.entrypoints=front" | |
- "traefik.http.routers.simple_http.rule=PathPrefix(`/simple_http{regex:$$|/.*}`)" | |
- "traefik.http.routers.simple_http.middlewares=simple_http-stripprefix" | |
- "traefik.http.middlewares.simple_http-stripprefix.stripprefix.prefixes=/" | |
networks: | |
- traefik01 | |
- traefik02 | |
networks: | |
traefik01: | |
external: true | |
traefik02: | |
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.7' | |
services: | |
traefik01: | |
container_name: traefik01 | |
image: traefik:${TRAEFIK_IMAGE_VERSION:-v2.2.0} | |
ports: | |
- "81:80" | |
- "8081:8080" | |
environment: | |
- TRAEFIK_LOG_LEVEL=INFO | |
- TRAEFIK_ACCESSLOG=true | |
- TRAEFIK_PROVIDERS_DOCKER_EXPOSEDBYDEFAULT=false | |
- TRAEFIK_PROVIDERS_DOCKER=true | |
- TRAEFIK_PROVIDERS_DOCKER_NETWORK=traefik01 | |
- TRAEFIK_API_INSECURE=true | |
- TRAEFIK_ENTRYPOINTS_FRONT=true | |
- TRAEFIK_ENTRYPOINTS_FRONT_ADDRESS=:80 | |
networks: | |
- traefik01 | |
volumes: | |
- /var/run/docker.sock:/var/run/docker.sock:ro | |
security_opt: | |
- label:type:docker_t | |
traefik02: | |
container_name: traefik02 | |
image: traefik:${TRAEFIK_IMAGE_VERSION:-v2.2.0} | |
ports: | |
- "82:80" | |
- "8082:8080" | |
environment: | |
- TRAEFIK_LOG_LEVEL=INFO | |
- TRAEFIK_ACCESSLOG=true | |
- TRAEFIK_PROVIDERS_DOCKER_EXPOSEDBYDEFAULT=false | |
- TRAEFIK_PROVIDERS_DOCKER=true | |
- TRAEFIK_PROVIDERS_DOCKER_NETWORK=traefik02 | |
- TRAEFIK_API_INSECURE=true | |
- TRAEFIK_ENTRYPOINTS_FRONT=true | |
- TRAEFIK_ENTRYPOINTS_FRONT_ADDRESS=:80 | |
networks: | |
- traefik02 | |
volumes: | |
- /var/run/docker.sock:/var/run/docker.sock:ro | |
security_opt: | |
- label:type:docker_t | |
networks: | |
traefik01: | |
driver: bridge | |
name: traefik01 | |
traefik02: | |
driver: bridge | |
name: traefik02 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.7.8-alpine | |
ENV PYTHONUNBUFFERED=1 | |
ENV LC_ALL=C.UTF-8 | |
ENV LANG=C.UTF-8 | |
ENV FLASK_APP=app.py | |
ENV FLASK_RUN_HOST=0.0.0.0 | |
ENV FLASK_RUN_PORT=8080 | |
EXPOSE 8080 | |
RUN mkdir -p /code/flask-app | |
WORKDIR /code/flask-app | |
COPY requirements.txt ./ | |
RUN pip install -r requirements.txt | |
ADD . ./ | |
CMD flask run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flask | |
gunicorn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://medium.com/@iced_burn/reverse-proxy-in-traefik-with-subdirectories-eef4261939e