{"id":16095835,"url":"https://github.com/zeusdeux/echo-server","last_synced_at":"2025-04-05T20:15:29.628Z","repository":{"id":149116613,"uuid":"133066620","full_name":"zeusdeux/echo-server","owner":"zeusdeux","description":"An echo http and ws server using nginx for SSL termination in prod deployed using docker","archived":false,"fork":false,"pushed_at":"2018-12-12T21:48:19.000Z","size":60,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T14:56:43.549Z","etag":null,"topics":["docker","docker-container","echo-http","echo-server","letsencrypt","nginx","ssl","ssl-termination","ws-server"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zeusdeux.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-11T17:00:08.000Z","updated_at":"2018-12-12T21:48:20.000Z","dependencies_parsed_at":"2023-09-02T22:24:21.996Z","dependency_job_id":null,"html_url":"https://github.com/zeusdeux/echo-server","commit_stats":{"total_commits":20,"total_committers":1,"mean_commits":20.0,"dds":0.0,"last_synced_commit":"6836639eca75341a04bc4494a867a445dbce1481"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeusdeux%2Fecho-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeusdeux%2Fecho-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeusdeux%2Fecho-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeusdeux%2Fecho-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zeusdeux","download_url":"https://codeload.github.com/zeusdeux/echo-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393573,"owners_count":20931813,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-container","echo-http","echo-server","letsencrypt","nginx","ssl","ssl-termination","ws-server"],"created_at":"2024-10-09T17:09:08.674Z","updated_at":"2025-04-05T20:15:29.599Z","avatar_url":"https://github.com/zeusdeux.png","language":"JavaScript","readme":"# echo-server\n\nAn echo http and ws server using nginx for SSL termination in prod deployed using docker.\n\nRun for yourself `docker pull zeusdeux/echo-server \u0026\u0026 docker run -it -p 8585:8585 zeusdeux/echo-server`\nor try it at [https://echo.mudit.xyz/hello](https://echo.mudit.xyz/hello).\n\n## Motivation\n\nI made this project only to play with docker and deploying a docker service behind nginx and using nginx for ssl termination.\n\nIf you're looking for pristine code, this isn't the place. This was hacked together only to learn a few things.\n\n## What does it do?\n\nThis service runs in a docker container which uses node carbon LTS.\nIt exposes an http server on port 8585.\nThis server echoes back all http requests.\nIt also handles http UPGRADE requests to support websockets.\nThe websocket server (which uses the same http server as before) also echoes back whatever that is sent to it.\n\nThe image is published as a public image to the docker hub as zeusdeux/echo-server.\n\n## Docker prod run cmd\n\n`PORT=9000 docker run -d -t --rm -p ${PORT}:8585 zeusdeux/echo-server`\n\nThe `-d` will detach the container, run it in the background and print the container id.\nThis can be checked again using `docker ps`.\n\nThe `-t` allocates a pseudo-TTY. This is so that when we run `docker attach \u003ccontainer id\u003e` and then `ctrl-c` out of it, we only\nexit the allocated TTY and don't kill the running container (which will happen by default if you don't pass this option).\n\nThe `--rm` automatically removes the container when it exits so that we don't rack up tons of non-running containers as they use\ndisk space and my ec2 instance is tiny af.\n\nThe `-p` option exposes an internal port to a host port. For e.g., `-p 9000:8585` will expose port `8585` from the docker container\nas port `9000` in the host os. Therefore, if you have an http server running inside your docker container on port `8585` then to\naccess it on the host machine, you'd have to navigate to `localhost:9000`. Without this option, no internal ports are mapped to\nany host os ports. So, yeah, this is an important one. You can also use `-P` but that has different semantics.\n\nThe `${PORT}` part is just a bash-ism to use the `$PORT` env var.\n\n## nginx config\n\nI use nginx as my reverse proxy and for SSL termination for this project.\nI use [letsencrypt](https://letsencrypt.org/) for SSL certs.\n\nStick this config in `/etc/nginx/sites-available` and symlink it to `/etc/nginx/sites-enabled` as one would.\n\nIf you want to use it in nginx.conf directly, wrap it inside a `http {}` block.\n\n```nginx\nupstream echoServer {\n    # port exposed from the running docker container\n    server 127.0.0.1:9000;\n}\n\nserver {\n    listen 80;\n    # setup dns entries for these subdomains with your provider\n    server_name your.domain.com www.your.domain.com;\n\n    # for letsencrypt verification\n    location /.well-known/ {\n       root \u003cany folder really. keep in mind though to pass this as the value to -w option of certbot\u003e;\n    }\n\n    location / {\n       # redirect to https\n       return 301 https://your.domain.com;\n    }\n}\n\nserver {\n    listen 443;\n    server_name your.domain.com www.your.domain.com;\n\n    # certs generated by letsencrypt's certbot\n    ssl_certificate /etc/letsencrypt/live/your.domain.com/fullchain.pem;\n    ssl_certificate_key /etc/letsencrypt/live/your.domain.com/privkey.pem;\n    ssl on;\n\n    # magic\n    ssl_session_timeout 10m;\n    ssl_session_cache builtin:1000 shared:SSL:10m;\n    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;\n    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;\n    ssl_prefer_server_ciphers on;\n\n    # enable gzipping for all browsers and IE6+\n    # only for assets. not for websocket traffic though.\n    gzip on;\n    gzip_proxied any;\n    gzip_types text/plain text/xml text/css application/x-javascript;\n    gzip_vary on;\n    gzip_disable \"MSIE [1-6]\\.(?!.*SV1)\";\n\n    location / {\n        proxy_set_header X-Real-IP $remote_addr;\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n        proxy_set_header X-Forwarded-Proto $scheme;\n        proxy_set_header Host $host;\n        proxy_set_header X-NginX-Proxy true;\n        proxy_http_version 1.1;\n        proxy_pass http://echoServer;\n        proxy_redirect off;\n        proxy_set_header Upgrade $http_upgrade;\n        proxy_set_header Connection \"upgrade\";\n        proxy_read_timeout 9999;\n    }\n}\n```\n\n## Some helpful docker commands\n\n- `docker ps` - view list of running containers\n- `docker system prune` - clean up dangling images and containers\n- `docker attach \u003ccontainer id\u003e` - attach to a running container. Be aware that ctrl-c from here might kill your container too depending on the options you ran the cotainer with\n- `docker exec -it \u003ccontainer id\u003e /bin/sh` - open up a terminal into the running container (not sure if this is the recommended way to do this though)\n- `docker kill \u003ccontainer id\u003e` - kill the running container\n\n## Some helpful nginx commands\n\n- `nginx -t` - test nginx config. This is very _very_ useful\n- `nginx -s stop` - stop nginx. Though, I would recommend using your service manager for this. For e.g., `sudo service nginx restart/stop/start` on Ubuntu\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeusdeux%2Fecho-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzeusdeux%2Fecho-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeusdeux%2Fecho-server/lists"}