Код: Выделить всё
db_read_timeЯ пытался записать заголовок, но кажется, что nginx не может его найти, в В документации nginx, которую я вижу, говорится, что upstream_http_db_read_time относится только к последнему ответу сервера, поэтому я предполагаю, что по какой-то причине он видит только заголовок из бэкэнда, а не аутентификацию.
Мне нужен способ получить заголовок от службы аутентификации и переслать его серверной службе.
Служба аутентификации:
`
Код: Выделить всё
@RequiredArgsConstructor
@RestController
public class AuthenticationController {
private final JdbcTemplate jdbcTemplate;
@GetMapping("/authenticate")
public ResponseEntity test(@RequestHeader("Authorization") String authorizationHeader) {
return ResponseEntity.ok()
.header("db_read_time", "123").body("placeholder");
}
}
конфигурация nginx:
`
Код: Выделить всё
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
log_format custom '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'"$upstream_http_db_read_time"';
access_log logs/access.log custom;
server {
listen 80;
server_name localhost;
location /api/ {
auth_request /auth;
proxy_pass http://localhost:5000;
proxy_set_header Host $host;
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;
proxy_set_header DB-Read-Time $upstream_http_db_read_time;
}
location = /auth {
internal;
proxy_pass http://localhost:5001/authenticate;
proxy_set_header Content-Type application/x-www-form-urlencoded;
proxy_set_header X-Original-URI $request_uri;
proxy_set_header Authorization $http_authorization;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
Журнал nginx:
`
Код: Выделить всё
127.0.0.1 - student [04/Oct/2024:17:15:52 +0300] "GET /api/hello HTTP/1.1" 200 27 "-" "curl/8.1.2" "-" "-"
Подробнее здесь: https://stackoverflow.com/questions/790 ... kend-servi
Мобильная версия