Skip to content

Instantly share code, notes, and snippets.

@maretekent
Forked from jessedearing/gist:2351836
Created September 15, 2018 08:24
Show Gist options
  • Save maretekent/cd39b3da62488fbe05e5ccf6d550d1e9 to your computer and use it in GitHub Desktop.
Save maretekent/cd39b3da62488fbe05e5ccf6d550d1e9 to your computer and use it in GitHub Desktop.
Create self-signed SSL certificate for Nginx
#!/bin/bash
echo "Generating an SSL private key to sign your certificate..."
openssl genrsa -des3 -out myssl.key 1024
echo "Generating a Certificate Signing Request..."
openssl req -new -key myssl.key -out myssl.csr
echo "Removing passphrase from key (for nginx)..."
cp myssl.key myssl.key.org
openssl rsa -in myssl.key.org -out myssl.key
rm myssl.key.org
echo "Generating certificate..."
openssl x509 -req -days 365 -in myssl.csr -signkey myssl.key -out myssl.crt
echo "Copying certificate (myssl.crt) to /etc/ssl/certs/"
mkdir -p /etc/ssl/certs
cp myssl.crt /etc/ssl/certs/
echo "Copying key (myssl.key) to /etc/ssl/private/"
mkdir -p /etc/ssl/private
cp myssl.key /etc/ssl/private/
@maretekent
Copy link
Author

sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain /etc/ssl/certs/myssl.crt

@maretekent
Copy link
Author

nginx_custom.conf on /usr/local/etc/nginx/nginx_custom.conf

events {}
http {
    upstream backend {
        server 127.0.0.1:8000;
    }
    server {
        server_name local.website.dev;
        rewrite ^(.*) https://local.website.dev$1 permanent;
    }
    server {
        listen               443;
        ssl                  on;
        ssl_certificate      /path/to/file/localhost.crt;
        ssl_certificate_key  /path/to/file/localhost.key;
        ssl_ciphers          HIGH:!aNULL:!MD5;
        server_name          local.website.dev;
        location / {
            proxy_pass  http://backend;
        }
    }
}

@maretekent
Copy link
Author

START nginx

$ sudo nginx -c /path/to/file/nginx_custom.conf

RELOAD nginx

$ sudo nginx -c /path/to/file/nginx_custom.conf -s reload

@maretekent
Copy link
Author

python -m SimpleHTTPServer 8000

Pointing to proxy

@maretekent
Copy link
Author

sudo /usr/sbin/apachectl start

lsof -i :80

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