""中的nginx无效网址前缀与地图

时间:2017-01-30 16:19:16

标签: nginx proxy

proxy_pass如果我保持default http://127.0.0.1:9200取消注释,  但是使用以下代码映射到~^/kibana-devproxy_pass无法正常工作,如果我转到http://my.domain.com/kibana-dev,我会得到500

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}


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;
    keepalive_timeout  65;

    map $request_uri $target {
        #default http://127.0.0.1:9200;
        ~^/kibana-dev http://127.0.0.1:9200;
        ~^/kibana-test http://127.0.0.1:9100;
    }

    server {

        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        if ( $request_uri ~* ^/kibana-test ) {
        return 301 http://my.domain.com/_plugin/kibana;
        }

        if ( $request_uri ~* ^/kibana-dev ) {
        return 301 http://my.domain.com/_plugin/kibana;
        }

        location / {
        proxy_set_header X-Real-IP 1.2.3.4;
        proxy_http_version 1.1;
        proxy_set_header Connect "Keep-Alive";
        proxy_set_header Proxy-Connection "Keep-Alive";
        proxy_set_header Authorization "";
        proxy_pass $target;
        }

    }
}             

我也尝试过:

map $uri $target {
        /kibana-dev http://127.0.0.1:9200;
    }

知道为什么吗? 感谢

1 个答案:

答案 0 :(得分:1)

您的配置文件没有意义。

如果您提供URI http://my.domain.com/kibana-dev,则server块将执行:

return 301 http://my.domain.com/_plugin/kibana;

这会导致URI表示为/_plugin/kibana。新URI由location /块处理并执行:

proxy_pass $target;

此时,咨询map以确定$target的值default/_plugin/kibana值与npwv = 1 while npwv == 1: npw = input("Please enter new password.") npwc = input ("Please confirm new password") if npwc == npw: if npwc.isupper()== False: if npwc.islower()== False: if len(npwc) >= 8: if str.isdigit(npwc) == True: npw=npwc print("Your password has been changed") else: print("Your password must contain a number") npwv = 1 else: print("Your password must contain at least 8 characters.") npwv = 1 else: print("Your password must contain at least 1 upper case character.") npwv = 1 else: print ("Passwords don't match") npwv = 1 不匹配任何其他值。< / p>