Skip to content

Instantly share code, notes, and snippets.

@dagjaneiro
Last active August 5, 2021 18:00
Show Gist options
  • Save dagjaneiro/dc1e26d87e745b47c4e2596f6b54022c to your computer and use it in GitHub Desktop.
Save dagjaneiro/dc1e26d87e745b47c4e2596f6b54022c to your computer and use it in GitHub Desktop.
lvh.me ssl

Install nginx

$ brew install nginx

Edit nginx.conf

$ vim /usr/local/etc/nginx/nginx.conf

Change the content of the file to:

worker_processes  1;

events {
  worker_connections  1024;
}

http {
  keepalive_timeout  0;

  # Change this ports to your dev servers
  map $host  $port {
    default        3000;
    cti.lvh.me     3001;
  }

  server {
     listen               443 ssl;
     server_name          *.lvh.me;
     ssl_certificate      lvh.cert;
     ssl_certificate_key  lvh.key;
     ssl_session_cache    shared:SSL:1m;
     ssl_session_timeout  15m;
     ssl_ciphers  HIGH:!aNULL:!MD5;
     ssl_prefer_server_ciphers  on;

     rewrite_log on;

     location / {
      proxy_pass          http://127.0.0.1:$port;
      proxy_set_header    Accept-Encoding     "";
      proxy_set_header    Host                $host;
      proxy_set_header    X-Real-IP           $remote_addr;
      proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
      proxy_set_header    X-Forwarded-Proto   $scheme;
      add_header          Front-End-Https     on;
    }
  }
  include servers/*;
}

Generate Self-signed certificate

Go to http://www.selfsignedcertificate.com/ and input *.lvh.me as the server name.

After generating the certificate files run the following commands in your shell:

$ cd /usr/local/etc/nginx
$ curl <LINK_TO_YOUR_KEY_FILE>/_.lvh.me.key > lvh.key
$ curl <LINK_TO_YOUR_CERT_FILE>/_.lvh.me.cert > lvh.cert

Start nginx

$ sudo nginx

In case you need to edit nginx.conf reload your configuration:

$ sudo nginx -s reload

Change local policy to trust the certificate

Add the certificate to Keychain Access and set the Trust Policy to Always Trust.

@gordonk
Copy link

gordonk commented Jun 29, 2017

To anyone else coming to this excellent tutorial, note I had to make some amendments creating the certificate due to Chrome 58+ enhanced security requirements. (note Mac OS)

openssl req \ -key lvh.key\ -x509 \ -nodes \ -new \ -out lvh.crt \ -subj "/CN=*.lvh.me" \ -reqexts SAN \ -extensions SAN \ -config <(cat /System/Library/OpenSSL/openssl.cnf \ <(printf '[SAN]\nsubjectAltName=DNS:lvh.me,DNS:*.lvh.me')) \ -sha256 \ -days 3650

@acrogenesis
Copy link

acrogenesis commented Jan 11, 2018

This one worked for me

openssl req -x509 -newkey rsa:4096 -keyout lvh.key -out lvh.cert -days 365 -subj '/CN=*.lvh.me' -nodes

The .cert is the one you have to add to your keychain

@josephan
Copy link

Awesome thanks! You can also start nginx with: brew services start nginx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment