Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Managing local SSL certificates without port
Dimas López
Dimas López

Posted on • Edited on

Managing local SSL certificates without port

CLI version herehttps://dev.to/dimaslz/managing-local-ssl-certificates-without-port-cli-4lfm

Sometimes we need to use HTTPS domain while we are working locally and, we use the basic url with the port where is running the project likehttps://localhost:3000. Also, sometimes, is recommended to have a similar TLD as the real domain in production, something likehttps://local.your-domain.com:3000, because maybe, we need to do something related to the TLD, like handle default language or something else.

As you can see, we need to add the PORT (3000). What happen if you want to remove the port in the url but, serving the application running in a port? You can not do it. You only can use 1 application running in the port 443 and, you need to add a special setting to the runner of the project, to serve the application in the 443 port (ssl). Other solutions are a bit complex, modifying something in your system manually probably (manually multiple times === will be tedious).

I try to avoid specific settings just for local environment, the project should have the less or any differences as possible with the production setting.

Also, another nuisance using the ports in the url, in my opinion, is when you have the URL set in multiple services, like Github, to make the authentication process. Then, if you need to change the port for some reason, you need to back to Github and update the port.

As I like automation scripts, I have created a script to automate to create local certifications (supported bymkcert) and remove the PORT's from the url through a proxy with Docker image base on Nginx.

How this proxy works

Here the Github repository if you want to try it:https://github.com/dimaslz/local-ssl-management-docker

(copied and pasted from:https://github.com/dimaslz/local-ssl-management-docker#how-to-use)

How to use

#1 - Update your /etc/hosts:

OSX:

...127.0.0.1        local.your-domain.com
Enter fullscreen modeExit fullscreen mode

#2 - Setup config:

[{"domain":"local.your-domain.com","port":3000,//wheretheapplicationisrunninghttp://localhost:3000},...]
Enter fullscreen modeExit fullscreen mode

#3 - Run your application:

The script will work but, if your application is not running, the domain will not resolve the source.

#4 - Run the script:

Before all, build the script by runningyarn build and afteryarn up

The script will:

  • Check theconfig.json file, creating the new SSL certificates if needed.
  • Create thenginx.conf per each domain.
  • Generate theDockerfile configuration.
  • Remove and create the new image (namedlocal-ssl-management).
  • Remove and create the new container (namedlocal-ssl-management).

All files will be into.temp folder (do not touch it).

#4 - Go to your domain and check it:

Open the application url:https://local.your-domain.com and... should work 😅.

END!

This is something that works for me, and maybe it works for you too.

I will continue working on it, this is my next iteration:

  • Add certs manually
  • Add custom nginx config
  • CLI

Feedback are welcome. If you like it, give me a ⭐️ in Githubhttps://github.com/dimaslz/local-ssl-management to motivate me to continue sharing work.

Thank you for reading and, happy coding! 👨‍💻

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Software developer · JS LoverWorking self projects.https://randomdata.loremapi.iohttps://ng-heroicons.dimaslz.devhttps://svg-icon-2-fw-component.dimaslz.dev
  • Location
    Barcelona
  • Work
    Software Engineer
  • Joined

More fromDimas López

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp