mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2026-02-05 00:29:40 +03:00
Nginx config for putting Bitwarden_rs behind a subfolder-based reverse proxy #549
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @UntouchedWagons on GitHub (Dec 31, 2019).
I wanted to put bitwarden behind a subfolder-based reverse proxy rather than a subdomain-based one so I bodged this together in about 5 minutes:
The locations after the first one could be cleaned up a bit, I'm not entirely sure how nginx's location directive works. If Bitwarden didn't assume that its base folder was / I think the last four location blocks wouldn't be needed.
@dani-garcia commented on GitHub (Jan 4, 2020):
We could potentially allow using a subdirectory in the server side, but note that this will break the web vault, the rest of the clients should work fine though.
There are some old patches to fix the web vault in this old issue if you are interested, and an apache config if that helps as well: https://github.com/dani-garcia/bitwarden_rs/issues/241#issuecomment-436376497
@Hobbabobba commented on GitHub (Feb 27, 2020):
the container updated to 1.13.1 (before i used 1.13.0 without any problem) and the reverse proxy doesn´t work anymore. The clients can´t connect to the server and i even can´t use the web vault.
@jjlin commented on GitHub (Feb 27, 2020):
@Hobbabobba I assume your instance is accessed via a subdir since you're commenting on this issue. As of a few days ago, there's builtin support for that (https://github.com/dani-garcia/bitwarden_rs/wiki/Using-an-alternate-base-dir), so you may need to adjust your bitwarden_rs and/or reverse proxy config.
@UntouchedWagons commented on GitHub (Feb 29, 2020):
I tried changing the DOMAIN environment variable and putting bitwarden behind an nginx reverse proxy, but Bitwarden is trying to access resources at
https://my-domain.site/instead ofhttps://my-domain.site/bitwarden/and all I get is a white page saying "Bitwarden"Also my test docker container's health is Unhealthy for some reason.
@rssw commented on GitHub (Mar 22, 2020):
I'm having difficulty setting this up. Is there a reference docker / nginx / bitwarden config with this working?
My experience is the same as UntouchedWagons. Bitwarden seems to be ignoring my DOMAIN variable in either the environment or the config.json files.
@jjlin commented on GitHub (Mar 22, 2020):
Try enabling the admin page. It should show you all config settings in effect.
@jjlin commented on GitHub (Mar 23, 2020):
Also, you need to pass the path through to the backend. For example,
would be wrong because when bitwarden_rs is configured with
DOMAIN=https://bw.example.com/bitwarden, the backend API routes are configured to expect the/bitwardenpath component.According to http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass, you should be able to just use
@rssw commented on GitHub (Mar 23, 2020):
Thanks for the support!
nginx config (i have many other services running in subdirectories, this one just adds the following)
docker-compose.yml
bitwarden.env
config.json
Just on the above, do I still need to expose 3012 port? Do I need to handle that separately in the reverse proxy? There is an example config to that effect in the docs, but it relates to a different configuration and perhaps a different version of bitwarden?
The result of the above is that Rocket responds with "The requested resource could not be found". Which is not nothing, it at least means that I'm reaching the bitwarden container! If I go against your advice, and add the trailing slash in the nginx config's proxy_pass directive, I actually reach bitwarden! But... The admin page is missing style information, and the signup process cannot be completed, so it's not really working. :(
But his behavior is why I suspect that my DOMAIN config is being ignored. Bitwarden still seems to handle requests from the root instead of the sub-directory.
Thoughts?
@jjlin commented on GitHub (Mar 23, 2020):
I don't run nginx for my setup, so just FYI, I'm not giving any authoritative advice on nginx specifics.
But maybe try an explicit
You do need to publish port 3012 if you want Websocket notification support. This is nice to have, but not necessary for a basic setup, so you could fix that later. You would need nginx to proxy to port 3012 as in the proxy examples in the wiki.
Anything in
config.jsonoverrides the corresponding env var, see https://github.com/dani-garcia/bitwarden_rs/wiki/Configuration-overview. If you can see anything in your admin page, verify the "Domain URL" (under the "General settings" section); it should behttps://bw.example.com/vaultin your example. You can also look under "Read-Only Config" and verify "Domain origin" ishttps://bw.example.comand "Domain path" is/vault, though that's unlikely to be an issue if your "Domain URL" is set properly.The request/response logging should also indicate if your subpath setting is in effect. Instead of, say,
POST /identity/connect/token, you should seePOST /vault/identity/connect/tokenif you're running properly under/vault.@rssw commented on GitHub (Mar 24, 2020):
Genius!!
Working as advertised! Thank you!
Just for completeness, can you elaborate on how / where to review the request/response logs?
J
@jjlin commented on GitHub (Mar 24, 2020):
Logs are printed to stdout, unless you configured it to log to file or syslog. If running with Docker, use
docker logs <container>to view the logs.@dani-garcia commented on GitHub (May 14, 2020):
We now allow running in a subfolder so this can be closed. Check the wiki for instructions.