2015-11-16 40 views
1

我需要在同一臺服務器上安裝uWSGI應用程序和Kibana4/elastic搜索堆棧。只有當用戶通過[server_IP]/charts /訪問服務器時才需要使用uwsgi應用程序,並且我希望通過[Server_IP]訪問Kibana4。重定向端口80請求基於路徑的不同應用程序

兩者都通過自己單獨的conf文件監聽端口80,可以預見,uwsgi應用程序不允許Kibana4接收請求。

如何調整我的conf文件以允許我需要的訪問權限?我有點困惑,我需要使用(重寫,重定向,別的東西嗎?)

感謝您的時間

nginx_conf_for_uwsgi:

server { 
    server_name   192.168.250.37; 
    listen    80; 
    root     /usr/local/wsgi; 
    access_log   /var/log/nginx/graph_server/access.log; 
    error_log    /var/log/nginx/graph_server/error.log; 
    client_max_body_size 500M; 
    proxy_read_timeout 600; 

location/{ 
    include    uwsgi_params; 
    uwsgi_pass   192.168.250.37:9091; 
    uwsgi_read_timeout 600; 
    } 
} 

kibana4.conf:

server { 
    listen 80; 

    server_name 192.168.250.37; 

    #auth_basic "Restricted Access"; 
    #auth_basic_user_file /etc/nginx/htpasswd.users; 

    location/{ 
     proxy_pass http://192.168.250.37:5601; 
     proxy_http_version 1.1; 
     proxy_set_header Upgrade $http_upgrade; 
     proxy_set_header Connection 'upgrade'; 
     proxy_set_header Host $host; 
     proxy_cache_bypass $http_upgrade; 
    } 
} 

nginx.conf:

user    nginx; 
worker_processes 4; 
error_log   /var/log/nginx/error.log; 
pid    /run/nginx.pid; 

events { 
    worker_connections 1024; 
} 

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

    # Increase header buffer size (needed for PHP) 
    proxy_buffer_size  128k; 
    proxy_buffers   4 256k; 
    proxy_busy_buffers_size 256k; 

    # Update the logs to display the real IP address after removing the IP for 
    # the load balancers 
    set_real_ip_from redacted; # a 
    set_real_ip_from redacted; # b 
    real_ip_header  X-Forwarded-For; 
    real_ip_recursive on; 

    # Custom logger to display the subdomain folder (if applicable) 
    log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 
         '$status $body_bytes_sent "$http_referer" ' 
         '"$http_user_agent" "$http_x_forwarded_for"'; 
    log_format log_thing '$remote_addr - $remote_user [$time_local] ' 
           '"$request" $status $body_bytes_sent ' 
           '"$http_referer" "$http_user_agent" ' 
           '"$http_x_forwarded_for" sub:"$subdomain"'; 
    log_format i_server '$remote_addr - $remote_user [$time_local] ' 
           '"$request" $status $body_bytes_sent ' 
           'filename:"$http_filename"'; 

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

    sendfile   on; 
    keepalive_timeout 65; 

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

    server { 
     listen  80 default_server; 
     server_name localhost; 
     root   /usr/share/nginx/html; 

     include /etc/nginx/default.d/*.conf; 

     location/{ 
     } 

     error_page 404    /404.html; 
     location = /40x.html { 
     } 

     error_page 500 502 503 504 /50x.html; 
     location = /50x.html { 
     } 
    } 
} 

回答

2

一種方法是使用nginx作爲反向代理,這實際上就是你現在正在做的事情。這樣你就有一個監聽端口80的nginx虛擬主機,它轉發不同的位置來分隔監聽系統上不同端口的nginx虛擬主機。

你nginx的反向代理虛擬主機會是這個樣子,3條proxy_set_header線可如果所有的位置與他們一起被移動到服務器塊

server { 
listen 80; 
server_name 192.168.250.37; 
port_in_redirect off 

location/{ 
    proxy_pass http://127.0.0.1:8081; 
    proxy_set_header Host $host; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    } 

location /charts { 
    proxy_pass http://127.0.0.1:8082; 
    proxy_set_header Host $host; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    } 
} 

然後改變你Kibanaconf爲偵聽端口8081和uwsgi聽8082

或者,您可以將兩個虛擬主機合併爲一個,並需要爲每個位置下的根文件夾設置自定義別名並重新排列。

server { 
listen 80; 

server_name 192.168.250.37; 
root /usr/local/wsgi; 
client_max_body_size 500M; 
proxy_read_timeout 600; 
#auth_basic "Restricted Access"; 
#auth_basic_user_file /etc/nginx/htpasswd.users; 

location/{ 
    proxy_pass http://192.168.250.37:5601; 
    proxy_http_version 1.1; 
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection 'upgrade'; 
    proxy_set_header Host $host; 
    proxy_cache_bypass $http_upgrade; 
} 

location /charts { 
    include    uwsgi_params; 
    uwsgi_pass   192.168.250.37:9091; 
    uwsgi_read_timeout 600; 
    } 
} 
+0

這是爲了幫助 - 我欣賞它。 –

相關問題