Skip to content

Instantly share code, notes, and snippets.

@bbonamin
Created July 7, 2015 10:06
Show Gist options
  • Save bbonamin/96be60bad7fa5164a092 to your computer and use it in GitHub Desktop.
Save bbonamin/96be60bad7fa5164a092 to your computer and use it in GitHub Desktop.
SSL in Development with Nginx + Rails
  1. Install nginx brew install nginx
  2. Cd into the nginx directory /usr/local/etc/nginx
  3. Create a ssl directory, change and generate a dummy ssl cert: mkdir ssl cd ssl penssl req -new -newkey rsa:2048 -sha1 -days 365 -nodes -x509 -keyout server.key -out server.crt (just accept the default empty settings)
  4. Go back to the nginx directory cd ..
  5. Create or edit nginx.conf with the following settings:
events {
  worker_connections  1024;
}
http {
  server {
    listen 443 ssl;
    server_name local.dev;

    ssl on;
    ssl_certificate /usr/local/etc/nginx/ssl/server.crt;
    ssl_certificate_key /usr/local/etc/nginx/ssl/server.key;


    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Ssl on;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-SSL 1;
    }
  }
}
  1. Go back to your app directory and run the rails server: rails s
  2. Visit https://localhost:3000 and accept any certificate warnings
  3. ???????
  4. PROFIT!! BAM! You're done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment