Skip to content

Instantly share code, notes, and snippets.

@bugb
Last active October 27, 2024 19:00
Show Gist options
  • Select an option

  • Save bugb/e08f4edd1d7ba11706469ccd6cce1dfd to your computer and use it in GitHub Desktop.

Select an option

Save bugb/e08f4edd1d7ba11706469ccd6cce1dfd to your computer and use it in GitHub Desktop.

Revisions

  1. Chau Giang revised this gist Oct 14, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gist.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    Mongo DB works with raw TCP instead of HTTP so we need create `stream` with Nginx.

    Add the below code above `http` block in nginx config file (eg: `/etc/nginx/nginx.conf` for Ubuntu)

    ```
  2. Chau Giang renamed this gist Oct 10, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gistfile1.txt → gist.md
    Original file line number Diff line number Diff line change
    @@ -49,3 +49,5 @@ http {
    ```

    Here you can share your Mongo DB server to your friend with: `yourip:9999`
  3. Chau Giang created this gist Oct 10, 2019.
    51 changes: 51 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    Add the below code above `http` block in nginx config file (eg: `/etc/nginx/nginx.conf` for Ubuntu)

    ```
    stream {
    server {
    listen 9999;
    proxy_connect_timeout 1s;
    proxy_timeout 3s;
    proxy_pass stream_mongo_backend;
    }

    upstream stream_mongo_backend {
    server localhost:27017;
    }
    }

    ```

    The file after modified look like this:

    ```
    user www-data;
    worker_processes auto;
    pid /run/nginx.pid;
    include /etc/nginx/modules-enabled/*.conf;

    events {
    ....

    }

    stream {
    server {
    listen 9999;
    proxy_connect_timeout 1s;
    proxy_timeout 3s;
    proxy_pass stream_mongo_backend;
    }

    upstream stream_mongo_backend {
    server localhost:27017;
    }
    }

    http {
    ...
    }
    ...


    ```