虚拟上有一个系统,端口号为9200。
现在不想直接走这个端口,想通过nginx监听的80端口来访问。
但是location貌似一直匹配不上。有劳各位大佬指教。
nginx.conf
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.line.com;
location / {
root html;
index index.html index.htm;
}
# 这个是我想通过前缀识别到9200端口的请求,然后rewrite后面的地址,发送到9200去。
location /elasticsearch/ {
rewrite ^/elasticsearch/(.*) /$1;
proxy_pass http://127.0.0.1:9200;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
# 监听一个端口,来代理es
server {
listen 9001;
server_name www.line.com;
location / {
proxy_pass http://127.0.0.1:9200/;
}
}
}
通过端口访问,结果正常:
通过80端口走nginx代理,感觉location /elasticsearch/没有起到作用,要么就是rewrite了之后直接匹配到location / 去了:
直接监听一个端口9001,然后把这个端口的所有请求都代理到9200去,是可以的。
但是我现在就只想通过地址去做匹配并转发。
有劳各位大佬指点一下哪里出的问题,要咋的改下。。。
给你个网址 这个配置nginx的方法一次就能成功,按着步骤走就可以 http://www.cygdream.com/blog