Skip to content

Instantly share code, notes, and snippets.

View fer-ri's full-sized avatar

Ferri Sutanto fer-ri

  • Purwokerto, Indonesia
View GitHub Profile
@fer-ri
fer-ri / index.md
Last active June 4, 2016 19:20
Create Bing API Key Translator
@fer-ri
fer-ri / background-image.ts
Created May 24, 2016 06:33
Background Image Style Directive for Angular 2 and Ionic 2
import {Directive, ElementRef, Input} from '@angular/core';
@Directive({
selector: '[background-image]'
})
export class BackgroundImage {
private el: HTMLElement;
constructor(el: ElementRef) {
this.el = el.nativeElement;
@fer-ri
fer-ri / letsencrypt.md
Created March 13, 2016 08:56 — forked from xrstf/letsencrypt.md
Let's Encrypt on Ubuntu 14.04, nginx with webroot auth

Let's Encrypt on Ubuntu 14.04, nginx with webroot auth

This document details how I setup LE on my server. Firstly, install the client as described on http://letsencrypt.readthedocs.org/en/latest/using.html and make sure you can execute it. I put it in /root/letsencrypt.

As it is not possible to change the ports used for the standalone authenticator and I already have a nginx running on port 80/443, I opted to use the webroot method for each of my domains (note that LE does not issue wildcard certificates by design, so you probably want to get a cert for www.example.com and example.com).

Configuration

For this, I placed config files into etc/letsencrypt/configs, named after <domain>.conf. The files are simple:

@fer-ri
fer-ri / README.md
Created March 13, 2016 08:56 — forked from renchap/README.md
One-line certificate generation/renews with Letsencrypt and nginx

Prerequisites : the letsencrypt CLI tool

This method allows your to generate and renew your Lets Encrypt certificates with 1 command. This is easily automatable to renew each 60 days, as advised.

You need nginx to answer on port 80 on all the domains you want a certificate for. Then you need to serve the challenge used by letsencrypt on /.well-known/acme-challenge. Then we invoke the letsencrypt command, telling the tool to write the challenge files in the directory we used as a root in the nginx configuration.

I redirect all HTTP requests on HTTPS, so my nginx config looks like :

server {
@fer-ri
fer-ri / restart-service.sh
Last active May 7, 2023 11:39
Auto Restart PHP5-FPM When Down or Bad Gateway
#!/bin/bash
if curl --head -sf http://yourdomain.com/some-script.php -o /dev/null; then
echo "PHP FPM is up"
else
service php5-fpm restart && service nginx restart && service mysql restart
echo "Opps .. service was down" | mail -s "PHP-FPM Service Down" [email protected] -aFrom:[email protected]
fi
@fer-ri
fer-ri / README.md
Created March 5, 2016 11:09 — forked from nodesocket/README.md
The perfect Gulp.js

The perfect gulp.js file

Tasks

serve

Runs a connect web server, serving files from /client on port 3000.

uglify-js

@fer-ri
fer-ri / block.conf
Last active March 3, 2018 15:06
Nginx Config Sites Available With Redirect Non Www To Www
location ~* "(eval\()" { deny all; }
location ~* "(127\.0\.0\.1)" { deny all; }
location ~* "([a-z0-9]{2000})" { deny all; }
location ~* "(javascript\:)(.*)(\;)" { deny all; }
location ~* "(base64_encode)(.*)(\()" { deny all; }
location ~* "(GLOBALS|REQUEST)(=|\[|%)" { deny all; }
location ~* "(<|%3C).*script.*(>|%3)" { deny all; }
location ~ "(\\|\.\.\.|\.\./|~|`|<|>|\|)" { deny all; }
location ~* "(boot\.ini|etc/passwd|self/environ)" { deny all; }
location ~* "(thumbs?(_editor|open)?|tim(thumb)?)\.php" { deny all; }
@fer-ri
fer-ri / phpfpm-mon.cron
Created March 3, 2016 23:56 — forked from dougalcampbell/phpfpm-mon.cron
Crontab entry to monitor for php-fpm problems
## Auto-restart PHP when it's returning errors
#
# Make sure that http://localhost/test.php is an actual PHP script. If it starts returning
# 500 errors, restart the PHP-FPM service
* * * * * /usr/bin/curl --head -sf http://localhost/test.php -o /dev/null || /usr/sbin/service php5-fpm restart
@fer-ri
fer-ri / wordpress.sh
Created March 3, 2016 17:13
Simple Wordpress Installer
#!/bin/bash
FIND_PATH="/home/*/domains/*/public_html/"
AWK_DOMAIN_POS="5"
DB_NAME=""
DB_USER=""
DB_USER_PASS=""
DOMAIN=""
@fer-ri
fer-ri / query.sql
Created January 30, 2016 12:22
Wordpress Term Query
-- Get All Category
SELECT wp_terms.* FROM wp_terms, wp_term_taxonomy
WHERE wp_terms.term_id = wp_term_taxonomy.term_id AND wp_term_taxonomy.taxonomy = 'category';
-- Get all Post ID within "Uncategorized" Category
SELECT wp_posts.ID FROM wp_posts, wp_terms, wp_term_taxonomy, wp_term_relationships
WHERE
wp_terms.term_id = wp_term_taxonomy.term_id
AND wp_term_taxonomy.taxonomy = 'category'
AND wp_term_relationships.object_id = wp_posts.ID