简体   繁体   中英

Enable https on dockerised Mern app? Digital Ocean

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM