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!

Top comments (0)