# Sticky Sessions with Wordpress

**URL:** <https://community.traefik.io/t/sticky-sessions-with-wordpress/14446>\
**Category:** Traefik v2\
**Tags:** docker-swarm\
**Created:** [May 11, 2022, 9:41pm UTC](https://community.traefik.io/t/sticky-sessions-with-wordpress/14446 "2022-05-11T21:41:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![codeco1978](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/codeco1978/32/5327_2.png) [@codeco1978](https://community.traefik.io/u/codeco1978)\
**Post date:** [May 11, 2022, 9:41pm UTC](https://community.traefik.io/t/sticky-sessions-with-wordpress/14446/1 "2022-05-11T21:41:20Z")

</div>

(First of all sorry for my bad english)

Hello everyone! I am trying to set on my rasperry pi cluster (4 nodes) 3 wordpress replicas and 1 database.

That works but **when I'm trying to enter in wordpress I log in everytime I refresh or interact with wordpress** , that's because docker swarm's routing mesh

I'm trying to set sticky sessions to solve this problem. I investigated 3 days in many pages but I didn't find anything helpfull.

I'm doing a degree project and I'm getting stuck in this problem. I'll apreciatte if someone can help me and give me a example with this code below.

```auto
version: '3'

services:
  db:
    image: mariadb
    networks:
      - wpnetwork
    volumes:
      - data:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=1234
      - MYSQL_DATABASE=wordpress
      - MYSQL_USER=wordpress
      - MYSQL_PASSWORD=1234
    ports:
      - 3306:3306
    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints:
          - "node.hostname==worker3"

  web:
    image: wordpress
    depends_on:
      - db
    volumes:
      - wordpress:/var/www/html
    environment:
      - WORDPRESS_DB_USER=wordpress
      - WORDPRESS_DB_PASSWORD=1234
      - WORDPRESS_DB_HOST=db
    ports:
      - 8080:80
    deploy:
      mode: replicated
      replicas: 3
      placement:
        constraints:
          - "node.role==worker"
    networks:
      - wpnetwork

volumes:
  data:
  wordpress:

networks:
  wpnetwork:
    driver: overlay

```

---

<div class="post-metadata">

**Author:** ![tommoulard](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/tommoulard/32/2997_2.png) [@tommoulard](https://community.traefik.io/u/tommoulard)\
**Post date:** [May 12, 2022, 8:33am UTC](https://community.traefik.io/t/sticky-sessions-with-wordpress/14446/2 "2022-05-12T08:33:02Z")

</div>

Hello @codeco1978,

To enable stick sessions, did you try looking in the [documentation](https://doc.traefik.io/traefik/routing/services/#sticky-sessions) ?

You might need to add the label to enable it:

```yaml
    traefik.http.services.wp.loadbalancer.sticky.cookie: true

```

---

<div class="post-metadata">

**Author:** ![codeco1978](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/codeco1978/32/5327_2.png) [@codeco1978](https://community.traefik.io/u/codeco1978)\
**Post date:** [May 12, 2022, 11:24am UTC](https://community.traefik.io/t/sticky-sessions-with-wordpress/14446/3 "2022-05-12T11:24:10Z")

</div>

Thanks for your message Tom! 😄  
I have tried to do what is shown in the .yml file below but it still gives the same problem with sessions. I'm missing something?

```auto
version: "3.8"

services:
  traefik:
    image: traefik:v2.3
    deploy:
      mode: global
    networks:
      - traefik-net
    command:
      - "--log.level=DEBUG"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.app.address=:80"
    ports:
      - 3001:80
      - 8080:8080
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
    deploy:
      replicas: 1
      placement:
        constraints:
          - "node.role==manager"

  db:
    depends_on:
      - traefik
    image: mariadb
    restart: always
    networks:
      - traefik-net
    volumes:
      - mariadb:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=1234
      - MYSQL_DATABASE=wordpress
      - MYSQL_USER=wordpress
      - MYSQL_PASSWORD=1234
    ports:
      - 3306:3306
    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints:
          - "node.labels.ID==wp"

  web:
    image: wordpress
    depends_on:
      - db
    volumes:
      - wordpress:/var/www/html
    environment:
      - WORDPRESS_DB_USER=wordpress
      - WORDPRESS_DB_PASSWORD=1234
      - WORDPRESS_DB_HOST=db
    ports:
      - 8181:80
    deploy:
      mode: replicated
      replicas: 2
      placement:
        constraints:
          - "node.labels.ID==wp"
    networks:
      - traefik-net
    labels:
      - "traefik.enable: true"
      - "traefik.http.services.wp.loadbalancer.sticky.cookie: true"

volumes:
  mariadb:
  wordpress:

networks:
  traefik-net:
    external: true
    name: traefik-net

```

 ![image](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/8/81ef74dbae448472adf107ccc63172925bb39094.png)

---

<div class="post-metadata">

**Author:** ![tommoulard](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/tommoulard/32/2997_2.png) [@tommoulard](https://community.traefik.io/u/tommoulard)\
**Post date:** [May 12, 2022, 1:07pm UTC](https://community.traefik.io/t/sticky-sessions-with-wordpress/14446/4 "2022-05-12T13:07:53Z")

</div>

If you access your wp instance through `localhost:8081`, it does not go through Traefik, you are accessing it directly.

I suggest you to follow this user guide on how to do a basic web app with Traefik : [Traefik Docker Documentation - Traefik](https://doc.traefik.io/traefik/user-guides/docker-compose/basic-example/)
