Skip to content

Instantly share code, notes, and snippets.

@martianyi
Last active February 16, 2022 13:18
Show Gist options
  • Save martianyi/611467844ea8d417986a8958fa4a653a to your computer and use it in GitHub Desktop.
Save martianyi/611467844ea8d417986a8958fa4a653a to your computer and use it in GitHub Desktop.
Reverse proxy aws elasticsearch service using nginx
  1. 在elasticsearch域的同一vpc下开一台ec2机器,安装nginx
  2. 准备ssl证书
  3. 配置nginx如下
server {
    listen 443 ssl http2;
    server_name $host;
    rewrite ^/$ https://$host/_plugin/kibana redirect;

    ssl_certificate /path/to/fullchain.pem;
    ssl_certificate_key /path/to/privkey.pem;

    add_header Strict-Transport-Security max-age=2592000;

    location /_plugin/kibana {
        # Forward requests to Kibana
        proxy_pass https://$ES_endpoint/_plugin/kibana;
        proxy_pass_header Server;
        proxy_cookie_domain $ES_endpoint $host;
        proxy_cookie_path / /_plugin/kibana/;
        proxy_buffering off;
        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 Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;

    }
}

# HTTP server
server {
        listen 80;
        listen [::]:80;
        server_name $host;
        return 301 https://$host$request_uri;
}
  1. 启动nginx并访问
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment