Skip to content

Instantly share code, notes, and snippets.

View glavk's full-sized avatar
🏠
Working from home

Eugene Selivanov glavk

🏠
Working from home
  • Flowwow
  • Bangkok
  • 09:01 (UTC +07:00)
View GitHub Profile
@glavk
glavk / nginx_fastcgi_errors.md
Created May 7, 2024 05:27 — forked from CMCDragonkai/nginx_fastcgi_errors.md
NGINX: Common FastCGI Errors involving PHP-FPM

Common FastCGI Errors involving PHP-FPM

  1. 504 Gateway Timeout

    upstream timed out (110: Connection timed out) while reading response header from upstream
    

Means NGINX timed out reading the HTTP response header from upstream. This

@glavk
glavk / s3_janitor.sh
Last active May 22, 2023 14:15 — forked from eduardogspereira/s3_janitor.sh
Delete files from S3 that are older than X days.
#!/bin/bash
# You need to uncomment two lines for the script work.
# Please check the logic before use it.
main () {
#aws s3 ls $BUCKETNAME | grep -v ' PRE ' | grep -v ' 0 ' > data.txt
UNIXDAYS=$(date -d "$DAYS days ago" +%s)
while read LINE
do
@glavk
glavk / GeoIP Block NGINX Ubuntu 20.04.md
Created January 18, 2023 04:12 — forked from dunderrrrrr/GeoIP Block NGINX Ubuntu 20.04.md
Allow or block GeoIP in Nginx on Ubuntu 20.04

GeoIP Block NGINX Ubuntu 20.04

Block or filter IPs based on location in Nginx (tested on 1.18.0) on Ubuntu 20.04.

Install Nginx modules

To make use of the geographical filtering, we must first install the Nginx GeoIP module as well as the GeoIP database containing the mappings between visitors’ IP addresses and their respective countries. To do so, let’s execute:

$ sudo apt install libnginx-mod-http-geoip geoip-database
@glavk
glavk / RabbitMQ.md
Last active February 2, 2022 09:25
RabbitMQ staff

Users

Add new user user with password password and set all permissions with admin access for management plugin:

rabbitmqctl add_user user password
rabbitmqctl set_permissions user ".*" ".*" ".*"
rabbitmqctl set_user_tags user administrator
@glavk
glavk / script_stderr.md
Created November 21, 2021 07:49
Log scripts errors

Example of logging script error, e.g. cron job

Simulate output to stderr with exit code 1 and write stderr to fail.log. Then proccess file as you want, e.g. send message to slack.

(echo "Test error" >&2; exit 1) 2>>/tmp/fail.log || cat /tmp/fail.log
@glavk
glavk / mysql_repl.md
Last active September 22, 2021 05:14
MySQL replication

Create users for replication

On master (source):

CREATE USER 'repl'@'%.example.com' IDENTIFIED BY 'password';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%.example.com';
@glavk
glavk / daemon_shell.md
Created August 27, 2021 13:55
Shell script as daemon

Run shell script as daemon via systemd

Create a unit /etc/systemd/system/mydaemon.service:

[Unit]
Description=My daemon script

[Service]
ExecStart=/usr/local/bin/script.sh
@glavk
glavk / ebs_resize.md
Created February 3, 2021 15:17
Amazon EBS resize

Old EBS volumes example:

growpart /dev/xvda 1
resize2fs /dev/xvda1

New NVME volumes example:

growpart /dev/nvme0n1 1
resize2fs /dev/nvme0n1p1 
@glavk
glavk / config.inc.php.md
Last active January 30, 2021 19:00
PHPMyAdmin multiple servers
$i++;
$cfg['Servers'][$i]['verbose'] = 'Database Server 2';
$cfg['Servers'][$i]['host'] = '192.168.1.102';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
log_format postdata '$time_local $request $request_body';
location = /path {
access_log /var/log/nginx/postdata.log postdata;
proxy_pass http://localhost:8080; # <= set your port
}