如何设置Elasticsearch的nginx?

时间:2017-08-17 12:44:04

标签: elasticsearch nginx

我正在关注Plunker demo教程,以便在CentOS 7上设置Elasticsearch的nginx。我试图在本教程中运行第一个(非常简单的)示例。这是我的nginx.conf:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    server {
        listen 8080;

        location / {
            proxy_pass http://localhost:9200;
        }
    }

    #include /etc/nginx/conf.d/*.conf;
}

重新启动nginx后,运行 curl 'localhost:8080/_nodes/stats/http?pretty'给出:

<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.13.4</center>
</body>
</html>

虽然localhost:9200按预期工作。在/var/log/nginx/error.log中写了四行:

2017/08/17 14:56:48 [crit] 38481#38481: *4 connect() to [::1]:9200 failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: , request: "GET /_nodes/stats/http?pretty HTTP/1.1", upstream: "http://[::1]:9200/_nodes/stats/http?pretty", host: "localhost:8080"
2017/08/17 14:56:48 [warn] 38481#38481: *4 upstream server temporarily disabled while connecting to upstream, client: 127.0.0.1, server: , request: "GET /_nodes/stats/http?pretty HTTP/1.1", upstream: "http://[::1]:9200/_nodes/stats/http?pretty", host: "localhost:8080"
2017/08/17 14:56:48 [crit] 38481#38481: *4 connect() to 127.0.0.1:9200 failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: , request: "GET /_nodes/stats/http?pretty HTTP/1.1", upstream: "http://127.0.0.1:9200/_nodes/stats/http?pretty", host: "localhost:8080"
2017/08/17 14:56:48 [warn] 38481#38481: *4 upstream server temporarily disabled while connecting to upstream, client: 127.0.0.1, server: , request: "GET /_nodes/stats/http?pretty HTTP/1.1", upstream: "http://127.0.0.1:9200/_nodes/stats/http?pretty", host: "localhost:8080"

为什么有权利被拒绝?我应该设置一些权限吗?

1 个答案:

答案 0 :(得分:-1)

2017/08/17 14:56:48 [crit] 38481#38481: *4 connect() to [::1]:9200 failed (13: Permission denied) 

似乎用户nginx没有足够的权限来执行connect()。你可以解决一下:将你的nginx.conf的第1行更改为:

user root

试一试。