2017-08-17 55 views
0

我正在关注this教程,在CentOS 7上设置Elasticsearch的nginx infront。我试图在本教程中运行第一个(非常简单)的示例。这里是我的nginx.conf:如何设置Elasticsearch的nginx infront?

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" 

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

+0

https://stackoverflow.com/questions/23948527/13-permission-denied-while-connecting-to-upstreamnginx – xeye

回答

-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 

然后试试它。