Replies: 46 comments
-
Thanks a lot for this example @abrichr ! But unfortunately I think I'm missing something in the configuration. Let me try the explain. Even though I can access the Traefik UI over https:
What do you mean by "# remove depends_on"? I haven't removed anything in the docker-compose.yml. Do you see anything wrong? |
Beta Was this translation helpful? Give feedback.
-
If you don't get an error about It looks like the site is being served over https, but the certificate is invalid. It may take a few minutes for the certificate provided by LetsEncrypt to become valid, and if you accessed it before then, the certificate might be cached. Try accessing it from a different browser/computer. If it still isn't working take a look at the Traefik logs with There might also be more information in Firefox. Try clicking on the arrow to the right of the message in the first screenshot and see what it says. (I would look myself but it looks like https://stag.verva.fr/ is currently down.) Edit: looking at your commands above, it seems that this line:
Should be:
I've updated my original comment so that you only need to specify each bit of information once. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your reply @abrichr and the update of the commands. I think I'm close to make it work since I now seem to be able to call all the following over HTTPS:
But I still have an issue with the frontend which is throwing the error "Blocked loading mixed active content “http://verva.fr/api/v1/prices/”: My understanding of this error is that the frontend should be calling this services of the fastapi over HTTPS but it is calling it over HTTP. is it correct? Following the comment of @wolfieorama #239 (comment) I updated my docker-compose.yml with traefik.docker.network and traefik.docker.router labels but without any success: version: "3.6"
services:
proxy:
image: traefik:v2.2
networks:
- ${TRAEFIK_PUBLIC_NETWORK?Variable not set}
- default
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command:
# Enable Docker in Traefik, so that it reads labels from Docker services
- --providers.docker
# Add a constraint to only use services with the label for this stack
# from the env var TRAEFIK_TAG
- --providers.docker.constraints=Label(`traefik.constraint-label-stack`, `${TRAEFIK_TAG?Variable not set}`)
# Do not expose all Docker services, only the ones explicitly exposed
- --providers.docker.exposedbydefault=false
# Enable Docker Swarm mode
- --providers.docker.swarmmode
# Enable the access log, with HTTP requests
- --accesslog
# Enable the Traefik log, for configurations and errors
- --log
# Enable the Dashboard and API
- --api
deploy:
placement:
constraints:
- node.role == manager
labels:
# Enable Traefik for this service, to make it available in the public network
- traefik.enable=true
# Use the traefik-public network (declared below)
- traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
# Use the custom label "traefik.constraint-label=traefik-public"
# This public Traefik will only use services with this label
- traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
# traefik-http set up only to use the middleware to redirect to https
- traefik.http.middlewares.${STACK_NAME?Variable not set}-https-redirect.redirectscheme.scheme=https
- traefik.http.middlewares.${STACK_NAME?Variable not set}-https-redirect.redirectscheme.permanent=true
# Handle host with and without "www" to redirect to only one of them
# Uses environment variable DOMAIN
# To disable www redirection remove the Host() you want to discard, here and
# below for HTTPS
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.rule=Host(`${DOMAIN?Variable not set}`) || Host(`www.${DOMAIN?Variable not set}`)
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.entrypoints=http
# traefik-https the actual router using HTTPS
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.rule=Host(`${DOMAIN?Variable not set}`) || Host(`www.${DOMAIN?Variable not set}`)
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.entrypoints=https
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.tls=true
# Use the "le" (Let's Encrypt) resolver created below
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.tls.certresolver=le
# Define the port inside of the Docker service to use
- traefik.http.services.${STACK_NAME?Variable not set}-proxy.loadbalancer.server.port=80
# Handle domain with and without "www" to redirect to only one
# To disable www redirection remove the next line
- traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.regex=^https?://(www.)?(${DOMAIN?Variable not set})/(.*)
# Redirect a domain with www to non-www
# To disable it remove the next line
- traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.replacement=https://${DOMAIN?Variable not set}/$${3}
# Redirect a domain without www to www
# To enable it remove the previous line and uncomment the next
# - traefik.http.middlewares.${STACK_NAME}-www-redirect.redirectregex.replacement=https://www.${DOMAIN}/$${3}
# Middleware to redirect www, to disable it remove the next line
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.middlewares=${STACK_NAME?Variable not set}-www-redirect
# Middleware to redirect www, and redirect HTTP to HTTPS
# to disable www redirection remove the section: ${STACK_NAME?Variable not set}-www-redirect,
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.middlewares=${STACK_NAME?Variable not set}-www-redirect,${STACK_NAME?Variable not set}-https-redirect
db:
image: postgres:12
volumes:
- app-db-data:/var/lib/postgresql/data/pgdata
env_file:
- .env
environment:
- PGDATA=/var/lib/postgresql/data/pgdata
deploy:
placement:
constraints:
- node.labels.${STACK_NAME?Variable not set}.app-db-data == true
pgadmin:
image: dpage/pgadmin4
networks:
- ${TRAEFIK_PUBLIC_NETWORK?Variable not set}
- default
#depends_on:
# - db
env_file:
- .env
deploy:
labels:
- traefik.enable=true
- traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
- traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
- traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-http.rule=Host(`pgadmin.${DOMAIN?Variable not set}`)
- traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-http.entrypoints=http
- traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-http.middlewares=${STACK_NAME?Variable not set}-https-redirect
- traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-https.rule=Host(`pgadmin.${DOMAIN?Variable not set}`)
- traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-https.entrypoints=https
- traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-https.tls=true
- traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-https.tls.certresolver=le
- traefik.http.services.${STACK_NAME?Variable not set}-pgadmin.loadbalancer.server.port=5050
queue:
image: rabbitmq:3
# Using the below image instead is required to enable the "Broker" tab in the flower UI:
# image: rabbitmq:3-management
#
# You also have to change the flower command
flower:
image: mher/flower:0.9.4
networks:
- ${TRAEFIK_PUBLIC_NETWORK?Variable not set}
- default
env_file:
- .env
command:
- "--broker=amqp://guest@queue:5672//"
# For the "Broker" tab to work in the flower UI, uncomment the following command argument,
# and change the queue service's image as well
# - "--broker_api=http://guest:guest@queue:15672/api//"
deploy:
labels:
- traefik.enable=true
- traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
- traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
- traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.rule=Host(`flower.${DOMAIN?Variable not set}`)
- traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.entrypoints=http
- traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.middlewares=${STACK_NAME?Variable not set}-https-redirect
- traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.rule=Host(`flower.${DOMAIN?Variable not set}`)
- traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.entrypoints=https
- traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.tls=true
- traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.tls.certresolver=le
- traefik.http.services.${STACK_NAME?Variable not set}-flower.loadbalancer.server.port=5555
backend:
image: '${DOCKER_IMAGE_BACKEND?Variable not set}:${TAG-latest}'
#depends_on:
# - db
env_file:
- .env
environment:
- SERVER_NAME=${DOMAIN?Variable not set}
- SERVER_HOST=https://${DOMAIN?Variable not set}
# Allow explicit env var override for tests
- SMTP_HOST=${SMTP_HOST}
build:
context: ./backend
dockerfile: backend.dockerfile
args:
INSTALL_DEV: ${INSTALL_DEV-false}
deploy:
labels:
- traefik.enable=true
- traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.rule=PathPrefix(`/api`) || PathPrefix(`/docs`) || PathPrefix(`/redoc`) || PathPrefix(`/ws`)
- traefik.http.services.${STACK_NAME?Variable not set}-backend.loadbalancer.server.port=80
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.tls=true
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.tls.certresolver=le
#- traefik.frontend.rule=PathPrefix:/api,/docs,/redoc,/ws
#- traefik.port=80
#- traefik.tags=${TRAEFIK_TAG}
# Add the strapi headless CMS
strapi:
image: strapi/strapi
env_file:
- .env
networks:
- ${TRAEFIK_PUBLIC_NETWORK?Variable not set}
- default
volumes:
- ./cms:/srv/app
#ports:
# - '1337:1337'
deploy:
labels:
- traefik.enable=true
- traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
- traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
- traefik.http.routers.${STACK_NAME?Variable not set}-strapi-http.rule=Host(`strapi.${DOMAIN?Variable not set}`)
- traefik.http.routers.${STACK_NAME?Variable not set}-strapi-http.entrypoints=http
- traefik.http.routers.${STACK_NAME?Variable not set}-strapi-http.middlewares=${STACK_NAME?Variable not set}-https-redirect
- traefik.http.routers.${STACK_NAME?Variable not set}-strapi-https.rule=Host(`strapi.${DOMAIN?Variable not set}`)
- traefik.http.routers.${STACK_NAME?Variable not set}-strapi-https.entrypoints=https
- traefik.http.routers.${STACK_NAME?Variable not set}-strapi-https.tls=true
- traefik.http.routers.${STACK_NAME?Variable not set}-strapi-https.tls.certresolver=le
- traefik.http.services.${STACK_NAME?Variable not set}-strapi.loadbalancer.server.port=1337
celeryworker:
image: '${DOCKER_IMAGE_CELERYWORKER?Variable not set}:${TAG-latest}'
#depends_on:
# - db
# - queue
env_file:
- .env
environment:
- SERVER_NAME=${DOMAIN?Variable not set}
- SERVER_HOST=https://${DOMAIN?Variable not set}
# Allow explicit env var override for tests
- SMTP_HOST=${SMTP_HOST?Variable not set}
build:
context: ./backend
dockerfile: celeryworker.dockerfile
args:
INSTALL_DEV: ${INSTALL_DEV-false}
frontend:
image: '${DOCKER_IMAGE_FRONTEND?Variable not set}:${TAG-latest}'
networks:
- ${TRAEFIK_PUBLIC_NETWORK?Variable not set}
- default
build:
context: ./frontend
args:
FRONTEND_ENV: ${FRONTEND_ENV-production}
deploy:
labels:
- traefik.enable=true
- traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
- traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-http.rule=PathPrefix(`/`) || PathPrefix(`/ws`)
- traefik.http.services.${STACK_NAME?Variable not set}-frontend.loadbalancer.server.port=80
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-https.tls=true
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-https.tls.certresolver=le
volumes:
app-db-data:
networks:
traefik-public:
# Allow setting it to false for testing
external: ${TRAEFIK_PUBLIC_NETWORK_IS_EXTERNAL-true}
There is probably something wrong with Traefik but my knowledge is very limited on that side I have to say and I haven't seen anything in the documentation. Did you manage to make the frontend call the api over HTTPS without any issue? |
Beta Was this translation helpful? Give feedback.
-
Can you paste the code which issues this request? |
Beta Was this translation helpful? Give feedback.
-
Sure! In the frontend, the call is initiated in the method "mounted" from a component public async fetchPriceData(){
this.setPairList();
await dispatchGetPrices(this.$store, {pairs: this.pairs});
this.dispatchPrices(readPrices(this.$store));
} dispatchGetPrices calls the following action in the store export const actions = {
async actionGetPrices(context: MainContext, payload: { pairs: IPair[] }) {
console.log("inActionGetPrices...")
try {
const response = await api.getPrices(context.rootState.main.token,payload.pairs)
.then(function (response){
commitSetPrices(context, response.data);
console.log("response ="+response.data)
})
} catch (error) {
dispatchCheckApiError(context, error);
}
} the getPrices method is defined in async getPrices(token: string, data: IPair[]) {
return await axios.put<IPrice[]>(`${apiUrl}/api/v1/prices`, data, authHeaders(token));
} The sources are here: https://gitlab.com/Ceyrac/verva I just realized that I can login to the default admin interface https://verva.fr/login without any issue, in particular the "Blocked loading mixed active content" one: This makes me think as you suggest, that the issue is not Traefik related but more code related. I'll dig into that. |
Beta Was this translation helpful? Give feedback.
-
I had a similar issue where only one API call was being issued for HTTP for some reason, where all the other ones were being issued over HTTPS. I noticed that this was the only one which didn't have a trailing
Try changing this to the following and see if that helps:
@tiangolo any idea why this would happen? |
Beta Was this translation helpful? Give feedback.
-
Thanks for your reply @abrichr, much appreciated. |
Beta Was this translation helpful? Give feedback.
-
I found the issue! In my code I'm calling the strapi CMS endpoint with the URI - traefik.http.routers.${STACK_NAME?Variable not set}-strapi-http.rule=Host(`strapi.${DOMAIN?Variable not set}`) I need to find a way to either keep https://verva.fr:1337/coins working in prod or UPDATE: after adding the configuration for a new |
Beta Was this translation helpful? Give feedback.
-
Hello, I have the following problem I have all my services running in my droplet. Like : and traefik stack running the public traefik like :I can access the public traefik dashboard... but my app is not exposed and I get a 404 on port 80. Any advice? |
Beta Was this translation helpful? Give feedback.
-
Nevermind, solved by getting the latest version of docker-compose.yml. |
Beta Was this translation helpful? Give feedback.
-
Just want to chip in that in my situation it was the exact opposite of what abhichr described. Had the same mixed content errors where some calls were seemingly issued via HTTP for no apparent reason, and the fix was to replace
with
In the axios call. |
Beta Was this translation helpful? Give feedback.
-
Hi, I don't really understand how to configure the part with
I am running the app on AWS EC2 instance and my domain has been bought from OVH. I don't find where to add this Thanks a lot! |
Beta Was this translation helpful? Give feedback.
-
This is outside the scope of this project, and I am unfamiliar with OVH,
but a quick Google search led me to
https://docs.ovh.com/ca/en/domains/web_hosting_how_to_edit_my_dns_zone/
…On Mon, Mar 1, 2021 at 5:48 AM Thomas ***@***.***> wrote:
Hi,
I don't really understand how to configure the part with CNAME:
# Configure your DNS, e.g.:
# CNAME stag ec2-...amazonaws.com.
# CNAME traefik stag.foo.com
I am running the app on AWS EC2 instance and my domain has been bought
from OVH. I don't find where to add this CNAME part on OVH website.
Thanks a lot!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#322 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAF5DVZPTBUCYINLWJZN63LTBNWHBANCNFSM4T6Y4THQ>
.
|
Beta Was this translation helpful? Give feedback.
-
hey, thanks for writing this guide! i want to write guide and making thesis to deploy full stack website using this reference but first what configuration do you use to launch EC2? i am currently trying to use your guide to launch production environment but have no luck for it to work and now troubleshooting one by one. right now i am hosting it in :
|
Beta Was this translation helpful? Give feedback.
-
Everything else is default. Hope this helps! Please post the article here when it's up 👍 |
Beta Was this translation helpful? Give feedback.
-
I'm not using an amazon server I'm depoying on a VPS instance of 1&1 ionos server |
Beta Was this translation helpful? Give feedback.
-
i wonder why when i run
my image don't update correctly sometimes Edit: nvm i found you have to do
after build.sh to docker registry so it can update correctly but if you don't have huge amazon ec2 you can do
in local first this way when you use deploy.sh the image will update correctly because you have push it to docker hub |
Beta Was this translation helpful? Give feedback.
-
Hello, I tried to put the system online and it worked well but now I have a lot of changes to apply and that's why I wanted to make a fresh start by deleting the images and stopping all the containers. But for some reason, the container keeps on starting over and over with new ids. I tried "docker stop" "docker container rm -f", to update the restart policy to "unless-stopped" and to "no" but nothing keeps the containers from restarting do you have any insights? |
Beta Was this translation helpful? Give feedback.
-
There may be a bug in the code that your container is running that is causing the container to crash; try checking the logs. |
Beta Was this translation helpful? Give feedback.
-
Maybe I explained it badly but my container is not crashing. I just want to stop it to delete the db volume but it keeps on restarting everytime I use the stop/kill or rm command. |
Beta Was this translation helpful? Give feedback.
-
When you deploy a stack using docker swarm, killing the container will usually restart the associated service. If you want to start over, you'd need to find the corresponding stack using |
Beta Was this translation helpful? Give feedback.
-
After running for a while without any trouble the backend side of the app is not working anymore stag.mifarmacia.app I have either a 404 or a 502 error in the browser and this is the logs of the backend. Do you have any insights? |
Beta Was this translation helpful? Give feedback.
-
Why would you install this stack on Ubuntu while you could deploy the docker images directly on AWS? |
Beta Was this translation helpful? Give feedback.
-
Hi, I got my service online successfully and was adding some changes, but after I followed the steps to deploy the updates, I found out backend image is not running, and api returns 404. Everything else looks fine, didn't see any error when running |
Beta Was this translation helpful? Give feedback.
-
I'm working with ionos.es 1&1 where they have my domain and other elements so I thought it was more convenient. But do you have any insight into why I could have this particular error? (cause everything was working fine until this happened...) |
Beta Was this translation helpful? Give feedback.
-
for future who read this deploying in AWS, you need at least t2.small to run this operation in Amazon EC2 lower than that can cause some container not working properly i learn you can push your build to docker hub using
then use
so the EC2 can pull it from docker hub automatically, after you build it on your local. it's gonna take a while to update it, around 5 minutes for me |
Beta Was this translation helpful? Give feedback.
-
Thanks for this walk through. |
Beta Was this translation helpful? Give feedback.
-
I feel like I should leave this comment here, but what had me confused for a very long time is that I thought the |
Beta Was this translation helpful? Give feedback.
-
Please provide more details on this setup. |
Beta Was this translation helpful? Give feedback.
-
I haven't use this project for a while. I guess this all the documentation. Sorry |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We had some issues getting this project deployed into production with HTTPS, and judging from the number of related issues, it seems we are not the only ones. Here are step-by-step instructions we used to deploy on a fresh Ubuntu 20.04 AWS EC2 instance:
You should now be able to see your app at https://stag.foo.com, and the Traefik UI at https://traefik.stag.foo.com. It may take a couple of minutes for the certificate to become valid.
When changes are pushed to your repo, the following seems to be required in order to deploy:
For completeness, here are the Docker versions:
Hope someone finds this helpful!
Beta Was this translation helpful? Give feedback.
All reactions