use*_*473 5 nginx keycloak netflix-zuul nginx-reverse-proxy
我正在尝试设置 nginx + keycloak 来保护我的 Spring Boot 微服务。
我希望配置以下结构
internet ---https---> nginx --http--> keycloak and other protected microservices
keycloak <----http----> zuul and other microservices
Run Code Online (Sandbox Code Playgroud)
我不知道如何设置 nginx 以正确地将原始 https 请求传递给 http 后端服务器
这是我的配置:NGINX
server {
listen 443 ssl default_server;
server_name localhost;
ssl_certificate /etc/nginx/localhost.crt;
ssl_certificate_key /etc/nginx/localhost.key;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/ledgerrun.access.log;
proxy_set_header Host $host:443;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# keycloak redirect
location /auth {
proxy_pass https://keycloak:8443;
}
location / {
proxy_pass http://192.168.1.15:15700;
}
# all /lr-servies redirect to 15700
#location ~* ^/lr-(.*) {
# proxy_pass https://192.168.1.15:15700;
#}
}
Run Code Online (Sandbox Code Playgroud)
Keycloak 实例为 https 打开 8443,为 http 打开 8080。
Spring Cloud Zuul 配置如下
server:
port: "15700"
keycloak:
auth-server-url: "https://my.external.ip:8443/auth"
realm: "LedgerRunCTP"
public-client: true
resource: gateway-service
security-constraints[0]:
authRoles[0]: "user"
securityCollections[0]:
name: "internal services"
patterns[0]: "/swagger-ui.html"
Run Code Online (Sandbox Code Playgroud)
使用上述配置,一旦 keycloak 对用户进行身份验证,就会收到以下错误:
纯 HTTP 请求已发送到 HTTPS 端口
设置它以实现的正确配置是什么
- 只有 https 到 nginx
- nginx 背后的所有 http
| 归档时间: |
|
| 查看次数: |
606 次 |
| 最近记录: |