Skip to content

Instantly share code, notes, and snippets.

View mhmtkptn's full-sized avatar
🌴
On vacation

Mehmet Kaptan mhmtkptn

🌴
On vacation
View GitHub Profile
@mhmtkptn
mhmtkptn / letsencrypt_2017.md
Created May 5, 2018 22:23 — forked from cecilemuller/letsencrypt_2020.md
How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

There are two main modes to run the Let's Encrypt client (called Certbot):

  • Standalone: replaces the webserver to respond to ACME challenges
  • Webroot: needs your webserver to serve challenges from a known folder.

Webroot is better because it doesn't need to replace Nginx (to bind to port 80).

In the following, we're setting up mydomain.com. HTML is served from /var/www/mydomain, and challenges are served from /var/www/letsencrypt.

#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
@mhmtkptn
mhmtkptn / docker-compose.yml
Created April 9, 2018 17:26 — forked from twang2218/docker-compose.yml
HAProxy + Nginx + PHP with client IP attached (don't forget docker daemon option `--userland-proxy=false`)
version: '2'
services:
haproxy:
image: haproxy:alpine
volumes:
- ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg
ports:
- "80:80"
depends_on:
- nginx
@mhmtkptn
mhmtkptn / openssl_encrypt_decrypt.php
Created April 3, 2018 20:44 — forked from joashp/openssl_encrypt_decrypt.php
Simple PHP encrypt and decrypt using OpenSSL
<?php
/**
* simple method to encrypt or decrypt a plain text string
* initialization vector(IV) has to be the same when encrypting and decrypting
*
* @param string $action: can be 'encrypt' or 'decrypt'
* @param string $string: string to encrypt or decrypt
*
* @return string
*/
@mhmtkptn
mhmtkptn / sane-caching.nginx.conf
Created April 3, 2018 16:20 — forked from philipstanislaus/sane-caching.nginx.conf
Sample Nginx config with sane caching settings for modern web development
# Sample Nginx config with sane caching settings for modern web development
#
# Motivation:
# Modern web development often happens with developer tools open, e. g. the Chrome Dev Tools.
# These tools automatically deactivate all sorts of caching for you, so you always have a fresh
# and juicy version of your assets available.
# At some point, however, you want to show your work to testers, your boss or your client.
# After you implemented and deployed their feedback, they reload the testing page – and report
# the exact same issues as before! What happened? Of course, they did not have developer tools
# open, and of course, they did not empty their caches before navigating to your site.
@mhmtkptn
mhmtkptn / README.md
Created January 30, 2018 20:24 — forked from hofmannsven/README.md
My simply Git Cheatsheet
@mhmtkptn
mhmtkptn / json_clean_decode.php
Created January 27, 2018 00:34
Clean comments of json content and decode it with json_decode(). Work like the original php json_decode() function with the same params. Support comments like /* */ and //
<?php
/**
* Clean comments of json content and decode it with json_decode().
* Work like the original php json_decode() function with the same params
*
* @param string $json The json string being decoded
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays.
* @param integer $depth User specified recursion depth. (>=5.3)
* @param integer $options Bitmask of JSON decode options. (>=5.4)
* @return array/object
@mhmtkptn
mhmtkptn / nginx.conf
Created January 24, 2018 21:31 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048