Với cấu hình này:
server {
    listen 8080;
    location / {
        if ($http_cookie ~* "mycookie") {
            proxy_set_header X-Request $request;
            proxy_pass http://localhost:8081;
        }
    }
}
Tôi gặp lỗi này khi tải lại dịch vụ nginx:
Reloading nginx configuration: nginx: [emerg] "proxy_set_header" directive is not allowed here in /etc/nginx/conf.d/check_cookie.conf:5
nginx: configuration file /etc/nginx/nginx.conf test failed
Cấu hình này hoạt động tốt, nhưng nó không làm những gì tôi muốn:
server {
    listen 8080;
    location / {
        proxy_set_header X-Request $request;
        if ($http_cookie ~* "mycookie") {
            proxy_pass http://localhost:8081;
        }
    }
}
Tại sao tôi không thể đặt lệnh proxy_set_header bên trong mệnh đề if?
                  Xin đừng đăng chéo. stackoverflow.com/questions/16500594/ từ
                
                
                  
                    —
                    ceejayoz 
                    
                  
                
              
                  Tôi đã mở một cuộc trò chuyện để thảo luận về điều này. Chúng ta có thể tiếp tục cuộc thảo luận ở đó: chat.stackexchange.com/rooms/8745/nginx
                
                
                  
                    —
                    Neuquino