SSL in the local environment of Docker / Rails / puma

In the production environment of Docker / Rails / puma, part of CRUD cannot be done well by SSL communication, so I made the local environment SSL to try various things locally. I summarized the procedure at that time.

Premise

--The page can already be displayed with http connection --Use openssl to create certificate --Chrome is security and cannot be connected, so access it with firefox and verify the display and operation. --When accessing the page, a message saying that the communication is not secure is returned, but it can be displayed by selecting "Detailed information" → "Continue with awareness of danger".

Implementation procedure

#Move to the certificate installation directory
$ cd docker/nginx/ssl

$ openssl genrsa -out server.key 2048

#Registration information is appropriate. .. ..
$ openssl req -new -key server.key -out server.csr
Country Name (2 letter code) []:JP
State or Province Name (full name) []:Fukuoka prefecture
Locality Name (eg, city) []:Fukuoka city
Organization Name (eg, company) []:oreore
Organizational Unit Name (eg, section) []:oreore
Common Name (eg, fully qualified host name) []:localhost
Email Address []:[email protected]
A challenge password []:a123456

$ openssl x509 -days 3650 -req -signkey server.key -in server.csr -out server.crt

Prevent it from being uploaded to GitHub

.gitignore



/docker/nginx/ssl/server.crt
/docker/nginx/ssl/server.csr
/docker/nginx/ssl/server.key

Allow port 443 or fit the mount to the path with the certificate.

docker-compose.yml



nginx:
    build:
      context: .
      dockerfile: ./docker/nginx/Dockerfile
    ports:
      - '80:80'
      - '443:443' #add to
    volumes:
      - sockets:/app/tmp/sockets
      - ./docker/nginx/ssl:/etc/nginx/ssl #add to

Set the directory path where the certificate is located in "ssl_certificate" etc. Make it 301 redirect to https when accessing http.

docker/nginx/default.conf



upstream app {
  server unix:///app/tmp/sockets/puma.sock;
}

server {
  listen 80;
  server_name  _;
  return 301 https://$host$request_uri;
}

server {
  listen 443 ssl;
  server_name localhost;

  ssl_certificate     /etc/nginx/ssl/server.crt;
  ssl_certificate_key /etc/nginx/ssl/server.key;
  ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers         HIGH:!aNULL:!MD5;

#···abridgement
$ docker-compose up -d

reference

How to make puma server SSL accessible --ryotaku's Tech Blog Enable HTTPS in Rails development environment Rails + Puma development environment SSL-Qiita Enable SSL / HTTPS in Rails5 + puma's local environment-Qiita SSL (HTTPS) settings with Nginx! Create a self-signed certificate!

finally

Now that CRUD is done under the essential local https connection, I will replace it with the certificate for this production environment and verify it again.

Recommended Posts

SSL in the local environment of Docker / Rails / puma
Rails5.1 + puma SSL connection in local production environment
How to install Docker in the local environment of an existing Rails application [Rails 6 / MySQL 8]
Docker × Laravel HTTPS (SSL) communication in local environment
Run Redmine in the local environment of Windows10 Pro-Use Docker Desktop for Windows
Docker the development environment of Ruby on Rails project
Install by specifying the version of Django in the Docker environment
Setting the baseURL in the axios module of Docker environment Nuxt
The identity of params [: id] in rails
Show Better Errors in Rails + Docker environment
[Rails] Reset the database in the production environment
How to solve the local environment construction of Ruby on Rails (MAC)!
[Order method] Set the order of data in Rails
Self-hosting with Docker of AuteMuteUs in Windows environment
(Basic authentication) environment variables in rails and Docker
[Rails] Run LINEBot in local environment using ngrok
Improve the performance of your Docker development environment
Support out of support in docker environment using centos6
Rails Docker environment construction
[Rails & Docker & MySQL environment construction] Could not find gem ‘mysql2 (> = 0.4.4, <0.6.0)’ in any of the gem sources listed in your Gemfile.
Procedure for introducing Docker into the development environment of existing Rails applications [Rails, MySQL, Docker]
Introduce Docker to the development environment and test environment of existing Rails and MySQL applications
Migration error after Activerecord association in Rails5 + Docker environment (2)
Prepare the execution environment of Tomcat in IntelliJ Community
virtulbox + vagrant + Docker + nginx + puma + MySQL Rails environment construction
Migration error after Activerecord association in Rails5 + Docker environment
[Java] Get the file in the jar regardless of the environment
A command that definitely cleans the local docker environment
Environment construction method and troubleshooter at the time of joint development (rails, docker and github)
Docker monitoring-explaining the basics of basics-
What to do when ‘Could not find’ in any of the sources appears in the development environment with Docker × Rails × RSpec
Understand the basics of docker
[Docker] Rails 5.2 environment construction with docker
[Docker] List of errors that occurred when building the environment
Rails application development environment construction with Docker [Docker, Rails, Puma, Nginx, MySQL]
Exit code 1 occurs when Rails is stopped in Docker environment
I tried to build the environment of WSL2 + Docker + VSCode
[Rails] Where to be careful in the description of validation
[Rails] What to do if you accidentally install bundle in the production environment in your local environment
I tried to develop the cache function of Application Container Cloud Service in the local environment
I tried using Docker because I don't want to pollute the local environment in Microsoft Teams tab development of MS Learn
Use MailHog for checking emails in the development environment (using Docker)
One file of Docker x Laravel threat! Build a local development environment with the minimum configuration
Build Couchbase local environment with Docker
Examine the system information of AWS Lambda operating environment in Java
[Rails] Check the contents of the object
About the symbol <%%> in Rails erb
[Programming beginner] What to do when rails s becomes an error in the local development environment
Explanation of the order of rails routes
I tried to build the environment of PlantUML Server with Docker
Super beginner builds Rails6 + Postgresql environment with Docker to the end
Build environment with vue.js + rails + docker
Check the migration status of rails
Install laravel/Dusk in docker environment (laravel6)
Build a browser test environment using Capybara in the Docker development environment
Rails on Docker environment construction procedure
Install lsb_release from the command line when lsb_release fails in docker environment
Hit the Docker API in Rust
After learning Progate, I tried to make an SNS application using Rails in the local environment
Replace preview by uploading by clicking the image in file_field of Rails
[Environment construction with Docker] Rails 6 & MySQL 8