DEV Community

Cover image for Host a Reverse Proxy in Seconds
Matt Voget
Matt Voget

Posted on

Host a Reverse Proxy in Seconds

Need a publicly accessible reverse proxy? Want to skip testing with localhost? Blackbird has an easy solution.

Setting up the Proxy

First let’s configure a simple reverse proxy with nginx using the following nginx.conf:

server {
    listen 80;
    location / {
        proxy_pass "https://httpbin.org/";
    }
}
Enter fullscreen mode Exit fullscreen mode

All requests sent to this server will proxy out to httpbin.org — a nice tool for developing and testing this proxy with downstream servers/APIs.

Next, we’ll define a simple Dockerfile that uses our ngnix configuration to build an image:

FROM nginxinc/nginx-unprivileged

COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

USER 1000

CMD ["nginx", "-g", "daemon off;"]
Enter fullscreen mode Exit fullscreen mode

Hosting the Proxy with Blackbird

After installing the Blackbird CLI, we can publicly host this reverse proxy with a Blackbird deployment:

blackbird deployment create proxy -d Dockerfile -c .
  ✔ input validated
  ✔ environment is ready
  ✔ no matching mock instance found
  ✔ image successfully built
  ✔ image successfully pushed
  ✔ checking existing deployments
  ✔ creating application for deployment
  ✔ application deployment created
+-------+------------+----------+---------------------------------------------------------+
| NAME  | TYPE       | STATUS   | URL                                                     |
+-------+------------+----------+---------------------------------------------------------+
| proxy | deployment | Ready    | https://matts-org-a0696.blackbird-relay.a8r.io/proxy/   |
+-------+------------+----------+---------------------------------------------------------+

Enter fullscreen mode Exit fullscreen mode

Blackbird gave us a public host that is running our reverse proxy in a container - let’s try it out:

curl --request POST -d '{"message":"hello"}' \
https://matts-org-a0696.blackbird-relay.a8r.io/proxy/post

{
  "args": {}, 
  "data": "{\"message\":\"hello\"}", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Content-Length": "19", 
    "Content-Type": "application/json", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/8.6.0"
  }, 
  "json": {
    "message": "hello"
  }, 
  "url": "https://httpbin.org/post"
}
Enter fullscreen mode Exit fullscreen mode

Just like that, our reverse proxy is live and hosted 🚀

Happy proxying!

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

Try REST API Generation for MS SQL Server.

DevOps for Private APIs. With DreamFactory API Generation, you get:

  • Auto-generated live APIs mapped from database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay