How to setup MongoDB behind Nginx Reverse Proxy

前端 未结 4 554
醉酒成梦
醉酒成梦 2020-12-15 19:39

Hi guys I am trying to setup Nginx as a reverse proxy for accessing a MongoDB Database. By default Mongo listens to 27017 port. What I want to do, is redirect a hostname for

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 20:03

    I left this behind, but after some work done, I had to face this problem again and the solution popped in my mind this time!

    NGINX is basically an HTTP server, so by setting redirects and proxies the above way, it wraps all communication in HTTP protocol. So the error that is happening, is that while Mongo is expecting Raw TCP traffic, it is getting HTTP traffic.

    So the solution to this is to use NGINX's new stream module that is used for handling raw TCP traffic and setup your upstream server to point to mongodb instance.

    More Info : NGINX stream module

提交回复
热议问题