通过Nginx作为代理连接到AWS Neptune服务器

时间:2019-12-26 10:33:44

标签: nginx amazon-neptune

AWS Neptune是VPC专用的。我们无法从VPC外部访问它。因此,我在同一VPC中创建了一个实例,并在其中安装了Nginx。我这样配置nginx(跳过了侧面的配置部分)。

http {
  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';
  sendfile            on;
  #tcp_nopush          on;
  tcp_nodelay         on;
  keepalive_timeout   65;
  types_hash_max_size 2048;
  server {
    listen 8182;
    error_log  /var/log/nginx/neptune.error.log main;
    access_log  /var/log/nginx/neptune.access.log main;
    location / {
      proxy_pass <neptune_endpoint>:8182;
    }
  }
}

当我尝试访问Neptune时,每次遇到此错误。

{"requestId":"","code":"BadRequestException","detailedMessage":"Bad request."}

如果有人遇到此类问题,请帮助我。

2 个答案:

答案 0 :(得分:1)

尽管AWS Neptune具有http终端节点,但是当我尝试使用nginx时,它没有用。所以我尝试了nginx提供的不同指令。我想要的是 stream 指令。如果将来有人需要相同的解决方案,请发布答案。

stream {
  server {
    listen 8182;
    proxy_pass <neptune_endpoint>:8182;
  }
}

答案 1 :(得分:0)

您可以尝试一下,看看是否可行吗?我给它做了一个快速测试,看来还可以。

http {
        upstream neptune {
                server <neptune_endpoint_without_protocol>:8182;
                keepalive 15;
        }

        sendfile            on;
        tcp_nodelay         on;
        keepalive_timeout   65;
        types_hash_max_size 2048;
        server {
                listen 8182;
                error_log  /var/log/nginx/neptune.error.log;
                access_log  /var/log/nginx/neptune.access.log;
                location / {
                        proxy_pass http://neptune;
                        proxy_redirect off;
                        proxy_buffering off;

                        proxy_http_version 1.1;
                        proxy_set_header Connection "Keep-Alive";
                        proxy_set_header Proxy-Connection "Keep-Alive";
                }
        }
}