keycloak我们都以docker为例子,来讲一下https的部署。
upstream keycloak { server 192.168.*.*:8080; } server { server_name kc.lind.com; listen 443 ssl; ssl_certificate /usr/local/nginx/tls.crt; ssl_certificate_key /usr/local/nginx/tls.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location /{ return 301 https://$server_name/auth; } location /auth { proxy_pass http://keycloak/auth; proxy_set_header Host $server_name; proxy_set_header X-Forwarded-Proto $scheme; #决定了keycloak.js文件是走https,这个比较特殊 proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
PROXY_ADDRESS_FORWARDING它的最终作用:
- 在负责在https请求转发到http时,keycloak所有资源(包括keycloak.js)都会改写成https协议,一般我们不
- 在服务端可以返回真实的客户端IP地址
docker run --name keycloak -d -p 8080:8080 \ -e KEYCLOAK_USER=admin \ -e KEYCLOAK_PASSWORD=admin \ -e DB_VENDOR=MYSQL \ -e DB_ADDR=192.168.4.26 \ -e DB_DATABASE=keycloak \ -e DB_USER=*** \ -e DB_PASSWORD=*** \ -e JDBC_PARAMS='useSSL=false' \ -e TZ=Asia/Shanghai \ -e LANG=zh_CN.GB2312 \ -e PROXY_ADDRESS_FORWARDING=true \ #接收反向代码的Forwarded-For -e KAFKA_HOST=192.168.4.26:9092 \ -v /etc/localtime:/etc/localtime \ --privileged=true \ --restart=always \ keycloak/phone
https://localhost/auth,它将会代理到localhost:8080这个端口上。