在web目录下运行nginx反向代理的sinatra程序

我试图让Kibana在特定的web目录下运行在nginx后面。 或者换一种说法,我试图让nginx反向代理http://example.com/kibanahttp://localhost:5601/ ,这是Kibana sinatra应用程序运行的地方。

我已经用一个初始化脚本启动了Kibana,如果我从服务器上curl localhost url,我会得到预期的响应。 然而,导航到http://example.com/kibana/给我的信息, Sinatra doesn't know this ditty. 并build议/kibana/应该做些什么。 据推测,这是一个路由问题。

我的nginxconfiguration是这样的:

 server { listen 80; ## listen for ipv4; this line is default and implied listen [::]:80 default ipv6only=on; ## listen for ipv6 root /var/www; index index.html index.htm; # Make site accessible from http://localhost/ server_name _; location / { # First attempt to serve request as file, then # as directory, then fall back to index.html try_files $uri $uri/ /index.html; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } location /kibana/ { proxy_pass http://localhost:5601; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_redirect off; 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_pass http://127.0.0.1:5601; 

replace为

 proxy_pass http://127.0.0.1:5601/; 

试试这个: https ://serverfault.com/a/379679/82682(最终取代'/foo/Kibana-0.2.0')

 location /kibana { # rewrite before passing to proxy rewrite /kibana/(.*) /$1 break; proxy_pass http://127.0.0.1:5601; # include nginx' proxy-defaults include proxy_params; # serve static stuff directly from the static-directory location /kibana/favicon.ico { alias /foo/Kibana-0.2.0/static/favicon.ico; } location /kibana/images { alias /foo/Kibana-0.2.0/static/images; } location /kibana/lib { alias /foo/Kibana-0.2.0/static/lib; } }