Skip to content

Instantly share code, notes, and snippets.

@coresh
coresh / certbot-dns-mailcow
Created September 9, 2024 17:04 — forked from greenmoss/certbot-dns-mailcow
This script renews letsecnrypt SSL certificates using Cloudflare dns-1 renewal. It assumes you are using Mailcow.
#!/usr/bin/env bash
# This script renews letsecnrypt SSL certificates using Cloudflare dns-1 renewal
# It assumes you are using Mailcow
set -euo pipefail
# REQUIRED set these:
your_email=letsencrypt@your.domain
your_domain=mail.your.domain # only tested with single domain
cloudflare_ini_path=/root/.cloudflare # add your Cloudflare file here, called cloudflare.ini

Introduction

Because Varnish doesn't support SSL, most people choose a setup where Nginx SSL will forward all traffic to Varnish and Varnish will forward will forward the traffic it cannot handle back to nginx. Or worse, bind Varnish on port 80 and direct all traffic into Varnish. This will already degrade performance, because Varnish will purge more because static files are also taking up room in the cache.

Default configuration

Next up, the Nginx configuration of Magento will handle static files.

@coresh
coresh / my.cnf
Created August 23, 2024 13:49 — forked from fevangelou/my.cnf
Optimized my.cnf configuration for MySQL/MariaDB (on Ubuntu, CentOS, Almalinux etc. servers)
# === Optimized my.cnf configuration for MySQL/MariaDB (on Ubuntu, CentOS, Almalinux etc. servers) ===
#
# by Fotis Evangelou, developer of Engintron (engintron.com)
#
# ~ Updated December 2021 ~
#
#
# The settings provided below are a starting point for a 8-16 GB RAM server with 4-8 CPU cores.
# If you have different resources available you should adjust accordingly to save CPU, RAM & disk I/O usage.
#
@coresh
coresh / vpnns_down.sh
Created February 16, 2024 10:08 — forked from Ernillew/vpnns_down.sh
Shutdown vpn netns
#!/bin/bash
sudo ip netns pids vpn | xargs -rd'\n' sudo kill
sudo rm -rf /etc/netns/vpn
sudo sysctl -q net.ipv4.ip_forward=0
sudo iptables -D INPUT ! -i vpn0 -s 10.10.10.0/24 -j DROP
sudo iptables -t nat -D POSTROUTING -s 10.10.10.0/24 -o en+ -j MASQUERADE
sudo ip link del vpn0
sudo ip netns delete vpn
@coresh
coresh / vpnns_up.sh
Created February 16, 2024 10:08 — forked from Ernillew/vpnns_up.sh
Start OpenVPN inside network namespace
#!/bin/bash
sudo ip netns add vpn
sudo ip netns exec vpn ip addr add 127.0.0.1/8 dev lo
sudo ip netns exec vpn ip link set lo up
sudo ip link add vpn0 type veth peer name vpn1
sudo ip link set vpn0 up
sudo ip link set vpn1 netns vpn up
sudo ip addr add 10.10.10.1/24 dev vpn0
sudo ip netns exec vpn ip addr add 10.10.10.2/24 dev vpn1
sudo ip netns exec vpn ip route add 37.59.63.23 via 10.10.10.1 dev vpn1
@coresh
coresh / nginx.conf
Created February 3, 2024 11:29 — forked from jamescaldow/nginx.conf
Nginx config file with SSL/TLS, security, speed and Cloudflare optimisations. (Work in progress)
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
@coresh
coresh / vpn_namespace.md
Created January 24, 2024 12:48 — forked from EnigmaCurry/vpn_namespace.md
OpenVPN and browser specific network routing with ip netns

OpenVPN and browser specific network routing with ip netns

Create network bridge

A network bridge allows us to have a virtual router that we can plug multiple network interfaces into. The IP address is assigned to the bridge rather than the individual network interface.

Create the bridge device, br0 :

@coresh
coresh / file.php
Created October 29, 2023 20:33 — forked from qutek/file.php
[php] Replace special character using preg replace
<?php
//Remove from a single line string
$output = "Likening ‘not-critical’ with";
$output = preg_replace('/[^(\x20-\x7F)]*/','', $output);
echo $output;
//Remove from a multi-line string
$output = "Likening ‘not-critical’ with \n Likening ‘not-critical’ with \r Likening ‘not-critical’ with. ' ! -.";
$output = preg_replace('/[^(\x20-\x7F)\x0A\x0D]*/','', $output);
echo $output;
@coresh
coresh / Censure.php
Created October 29, 2023 10:28 — forked from serebro/Censure.php
Censure.php
<?php
/**
* Определение наличия мата (нецензурных слов) в тексте, матотест
*
* Алгоритм достаточно надёжен и быстр, в т.ч. на больших объёмах данных
* Метод обнаружения мата основывается на корнях и предлогах русского языка, а не на словаре
* Слова "лох", "хер", "залупа", "сука" матерными словами не считаются (см. словарь Даля)
* Разработка ведётся с 2005 года
*
* Класс явл. хорошим учебным пособием по изучению регулярных выражений и... русского мата! =)
@coresh
coresh / mkselfssl.sh
Created September 1, 2023 10:34 — forked from adrianorsouza/mkselfssl.sh
Script to create a new self-signed SSL Certificate for Nginx
#!/bin/bash
# @author Adriano Rosa (http://adrianorosa.com)
# @date: 2014-05-13 09:43
#
# Bash Script to create a new self-signed SSL Certificate
# At the end of creating a new Certificate this script will output a few lines
# to be copied and placed into NGINX site conf
#
# USAGE: this command will ask for the certificate name and number in days it will expire