Reputation: 33
I have built a MERN stack application, and separated my Nodejs(express) server & my React frontend into separate docker containers, and can launch them with a compose file.
im hoping to take it to production on a Digital Ocean Droplet running docker/docker-compose, and am wondering how to secure it with ssl? do i need to enable certificates on each container, or just the droplet.
while researching this topic i see many people using Nginx inside their frontend(React) but am unsure how this ties in?
Upvotes: 0
Views: 842
Reputation: 2531
The most common way to handle SSL is to add a Reverse Proxy
(Nginx for example) to do the SSL offloading for all of your environment.
+----------+
| |
| Client |
| |
+----+-----+
|
| myDomain.net
|
[INTERNET]
|
|
v :443
+--------+-------+
/* | | /api
+----------+ Revese Proxy +---------+
| | (Gateway) | |
| +----------------+ |
| |
| |
| :8080 | :3000
| |
+----+----------+ +---------+-----+
| | | |
| SPA | | Backend |
| (webserver) | | (API server) |
| | | |
+---------------+ +---------------+
You will need to add an additional component to your compose. You can call it gateway
. Now you can pass the SSL as a secret and now it will act as a middleware for your network that encrypts outgoing data and decrypt incoming.
I found a tutorial that may be a good fit for your setup: https://medium.com/@pentacent/nginx-and-lets-encrypt-with-docker-in-less-than-5-minutes-b4b8a60d3a71
Upvotes: 2