The original post: /r/nginx by /u/technician_902 on 2024-07-01 18:41:42.
Hi, I am trying to set up Vault behind an Nginx proxy, but each time I log into the UI and refresh the page, it logs me out and its not able to retrieve some of the ui files either. I think it has something to do with the way I have Nginx set up. Below are the setup files I have below. Any help would be great thanks
nginx.conf
events {
worker\_connections 1024;
}
http {
include mime.types;
default\_type application/octet-stream;
server {
listen 80;
location /vault/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Accept-Encoding "";
to proxy WebSockets in nginx
proxy_pass http://vault:8200/;
proxy_redirect /ui/ /vault/ui/;
proxy_redirect /v1/ /vault/v1/;
#rewrite html baseurl
sub_filter '' '';
#sub_filter_once on;
sub_filter '"/ui/' '"/vault/ui/';
sub_filter '"/v1/' '"/vault/v1/';
sub_filter_once off;
sub_filter_types application/javascript text/html;
}
location /v1 {
proxy_pass http://vault:8200;
}
}
}
vault-dev-server.hcl
storage "raft" {
path = "./vault/data"
node\_id = "node1"
}
listener "tcp" {
address = "0.0.0.0:8200"
tls\_disable = "true"
}
api\_addr="http://vault:8200"
cluster\_addr="https://vault:8201"
disable\_mlock = true
ui = true
docker-compose.yml
services:
nginx:
image: nginx:alpine
container\_name: nginx
ports:
- "9100:80"
volumes:
- ./setup/nginx.conf:/etc/nginx/nginx.conf:ro
depends\_on:
- vault
vault:
image: hashicorp/vault:latest
environment:
VAULT\_ADDR: http://vault:8200
VAULT\_DEV\_LISTEN\_ADDRESS: <http://0.0.0.0:8200>
VAULT\_DEV\_ROOT\_TOKEN\_ID: root
cap\_add:
- IPC\_LOCK
entrypoint: vault server -config=/vault/config/vault-dev-server.hcl
volumes:
- vault\_data:/vault/data
- ./setup/vault-dev-server.hcl:/vault/config/vault-dev-server.hcl
volumes:
vault\_data: