# Set secure cookie from container behind traefik

**URL:** <https://community.traefik.io/t/set-secure-cookie-from-container-behind-traefik/9348>\
**Category:** Traefik v2\
**Tags:** tcp, docker\
**Created:** [January 17, 2021, 8:45pm UTC](https://community.traefik.io/t/set-secure-cookie-from-container-behind-traefik/9348 "2021-01-17T20:45:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukaszlukasiewicz](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/lukaszlukasiewicz/32/3200_2.png) [@lukaszlukasiewicz](https://community.traefik.io/u/lukaszlukasiewicz)\
**Post date:** [January 17, 2021, 8:45pm UTC](https://community.traefik.io/t/set-secure-cookie-from-container-behind-traefik/9348/1 "2021-01-17T20:45:14Z")

</div>

I've two containers setup from separate docker-compose.yml files.  
Traefik:

```auto
version: "3.3"

services:

  traefik:
    image: "traefik:v2.3"
    container_name: "traefik"
    command:
      - "--log.level=DEBUG"
      - "--api=true"
      - "--api.dashboard=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--entrypoints.web.http.redirections.entrypoint.to=websecure"
      - "--entrypoints.web.http.redirections.entrypoint.scheme=https"
      - "--certificatesresolvers.myresolver.acme.httpchallenge.entrypoint=web"
      - "--certificatesresolvers.myresolver.acme.email=MY@EMAIL.COM"
      - "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
      
    networks:
      - web
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    volumes:
      - "./letsencrypt:/letsencrypt"
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.dashboard.rule=Host(`monitor.MYDOMAIN.COM`)"
      - "traefik.http.routers.dashboard.service=api@internal"
      - "traefik.http.routers.dashboard.entrypoints=websecure"
      - "traefik.http.routers.dashboard.tls.certresolver=myresolver"
      - "traefik.http.routers.dashboard.tls=true"
      - "traefik.http.routers.dashboard.middlewares=auth"      
      - "traefik.docker.network=web"
      - "traefik.http.middlewares.auth.basicauth.users=USER:PASS" 

networks:
  web:
    external: true

```

And strapi:

```auto
version: '3'
services:
  strapi:
    image: strapi/strapi
    environment:
      DATABASE_CLIENT: mongo
      DATABASE_NAME: strapi
      DATABASE_HOST: mongo
      DATABASE_PORT: 27017
      DATABASE_USERNAME: strapi
      DATABASE_PASSWORD: strapi
    links:
      - mongo:mongo
    volumes:
      - ./app:/srv/app
    ports:
      - "1337:1337"
    labels:
      - "traefik.docker.network=web"
      - "traefik.enable=true"
      - "traefik.basic.port=1337"
      - "traefik.basic.protocol=https"
      - "traefik.http.routers.strapi.rule=Host(`cms.MYDOMAIN.COM`)"
      - "traefik.http.routers.strapi.entrypoints=websecure"
      - "traefik.http.routers.strapi.tls.certresolver=myresolver"
      - "traefik.tcp.routers.strapi.tls.passthrough=true"
    networks:
      - web
  mongo:
    image: mongo
    environment:
      MONGO_INITDB_ROOT_USERNAME: USER
      MONGO_INITDB_ROOT_PASSWORD: PASS
    volumes:
      - ./data/db:/data/db
    ports:
      - '27017:27017'
    networks:
      - web
    labels:
      - "traefik.docker.network=web"
      - "traefik.enable=true"
      - "traefik.basic.port=27017"
      - "traefik.basic.protocol=http"
networks:
  web:
    external: true

```

Everything works fine (correct certificates, connection via https) until I try to set a secure cookie from strapi. Than I have following error:

```auto
strapi_1_8d6726e61bc7 | [2021-01-17T17:09:24.915Z] error Error: Cannot send secure cookie over unencrypted connection
strapi_1_8d6726e61bc7 | at Cookies.set (/srv/app/node_modules/cookies/index.js:94:11)
strapi_1_8d6726e61bc7 | at Object.callback (/srv/app/extensions/users-permissions/controllers/Auth.js:136:21)
strapi_1_8d6726e61bc7 | at async /srv/app/node_modules/strapi/lib/middlewares/router/utils/routerChecker.js:79:22
strapi_1_8d6726e61bc7 | at async module.exports (/srv/app/extensions/users-permissions/config/policies/permissions.js:88:3)
strapi_1_8d6726e61bc7 | at async /srv/app/node_modules/strapi-utils/lib/policy.js:68:5
strapi_1_8d6726e61bc7 | at async /srv/app/node_modules/strapi/lib/middlewares/parser/index.js:48:23
strapi_1_8d6726e61bc7 | at async /srv/app/node_modules/strapi/lib/middlewares/xss/index.js:26:9

```

Is there any solution for this?

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [January 17, 2021, 11:48pm UTC](https://community.traefik.io/t/set-secure-cookie-from-container-behind-traefik/9348/2 "2021-01-17T23:48:27Z")

</div>

Some software needs special configuration for deployment behind a reverse-proxy.

Check the documentation of the product.

---

<div class="post-metadata">

**Author:** ![lukaszlukasiewicz](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/lukaszlukasiewicz/32/3200_2.png) [@lukaszlukasiewicz](https://community.traefik.io/u/lukaszlukasiewicz)\
**Post date:** [January 18, 2021, 8:29am UTC](https://community.traefik.io/t/set-secure-cookie-from-container-behind-traefik/9348/3 "2021-01-18T08:29:12Z")

</div>

You are absolutely right 🙂 I feel stupid now, but adding "proxy:true" to strapi configuration fixed the problem 🤦‍♂️

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/b/bd81ebdb578656e76e56ff3cc3eed021d3ba132d.png) [@system](https://community.traefik.io/u/system)\
**Post date:** [January 21, 2021, 8:29am UTC](https://community.traefik.io/t/set-secure-cookie-from-container-behind-traefik/9348/4 "2021-01-21T08:29:17Z")

</div>

Closed on January 21, 2021, 8:29am UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
