Skip to content

Instantly share code, notes, and snippets.

@ztrange
ztrange / install-comodo-ssl-cert-for-nginx.rst
Created March 31, 2018 22:28 — forked from bradmontgomery/install-comodo-ssl-cert-for-nginx.rst
Steps to install a Comodo PositiveSSL certificate with Nginx.

Setting up a SSL Cert from Comodo

I use Namecheap.com as a registrar, and they resale SSL Certs from a number of other companies, including Comodo.

These are the steps I went through to set up an SSL cert.

Purchase the cert

@ztrange
ztrange / post-mortem.md
Created February 20, 2018 17:11 — forked from joewiz/post-mortem.md
Recovery from nginx "Too many open files" error on Amazon AWS Linux

On Tue Oct 27, 2015, history.state.gov began buckling under load, intermittently issuing 500 errors. Nginx's error log was sprinkled with the following errors:

2015/10/27 21:48:36 [crit] 2475#0: accept4() failed (24: Too many open files) 2015/10/27 21:48:36 [alert] 2475#0: *7163915 socket() failed (24: Too many open files) while connecting to upstream...

An article at http://www.cyberciti.biz/faq/linux-unix-nginx-too-many-open-files/ provided directions that mostly worked. Below are the steps we followed. The steps that diverged from the article's directions are marked with an *.

    • Instead of using su to run ulimit on the nginx account, use ps aux | grep nginx to locate nginx's process IDs. Then query each process's file handle limits using cat /proc/pid/limits (where pid is the process id retrieved from ps). (Note: sudo may be necessary on your system for the cat command here, depending on your system.)
  1. Added fs.file-max = 70000 to /etc/sysctl.conf
  2. Added `nginx soft nofile 1
@ztrange
ztrange / mongoose_5_conn.js
Last active January 20, 2018 20:59
Mongoose 5.0.1 connection with events for multiple connections
const mongoose = require('mongoose')
mongoose.Promise = global.Promise
// Connect to MongoDB on localhost:27017
const conn = mongoose.createConnection('mongodb://localhost:27017/test')
conn.once('open', () => console.log('ready to use OPEN'))
conn.on('connected', () => console.log('ready to use'))
conn.on('error', err => console.log(err))
#!/usr/bin/env bash
# Attach Data Disk AZURE specific
# https://docs.microsoft.com/en-us/azure/virtual-machines/linux/attach-disk-portal
# Grep for SCSI devices in the logs, such as in the following command and get the id of the last disk added. e,g, sdc
sudo grep SCSI /var/log/syslog
# create your device