# Gebruikerssessies behouden bij het migreren tussen hosts

**URL:** <https://meta.discourse.org/t/preserving-user-sessions-when-migrating-between-hosts/166451>\
**Category:** Self-hosting\
**Created:** [6 oktober 2020 om 22:07 UTC](https://meta.discourse.org/t/preserving-user-sessions-when-migrating-between-hosts/166451 "2020-10-06T22:07:27Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
**Post date:** [7 oktober 2020 om 12:28 UTC](https://meta.discourse.org/t/preserving-user-sessions-when-migrating-between-hosts/166451/8 "2020-10-07T12:28:28Z")

</div>

Session cookies are encrypted using a randomly generated secret key which, by default, is stored in redis. Redis data is not included in a backup so a new secret key is regenerated when you restore the site onto a new server.

> <https://github.com/discourse/discourse/blob/6e69c251348aae29af9ad504e1b01d431a751423/app/models/global_setting.rb#L18-L24>

You can manually set the secret key using an environment variable `DISCOURSE_SECRET_KEY_BASE` in your app.yml file. So you could try something like this to preserve sessions:

1. On your existing server, enter the console and find the secret key from redis

2. Add DISCOURSE\_SECRET\_KEY\_BASE to the `env:` section of your app.yml on the old server, using the value you found in (1), and rebuild the app. In theory, if everything went right, Discourse should now use the value from the app.yml, and user sessions will persist. You can check the env variable is being used by running

3. Make sure the app.yml on the new server has the same SECRET\_KEY\_BASE. When you restore the backup, the user sessions should persist

I haven’t tested that flow, so if you plan to use it for a production forum make sure to test it out first!

Side note: you absolutely **should not** share the secret key between multiple discourse instances. Possession of the secret key would allow someone to decrypt and modify their session cookie on a site, and could have very bad security consequences.

---

_[View the full topic](https://meta.discourse.org/t/preserving-user-sessions-when-migrating-between-hosts/166451)._
