Skip to content

Instantly share code, notes, and snippets.

View saniaky's full-sized avatar
👋

John Doe saniaky

👋
  • Web
  • Online
View GitHub Profile
@saniaky
saniaky / CheckPort.java
Last active February 21, 2023 16:16
Check if port is open
public static boolean serverListening(String host, int port) {
Socket s = null;
try {
s = new Socket(host, port);
log.info("OK -> HOST: {}, PORT: {}", host, port);
return true;
} catch (Exception e) {
log.info("CLOSED -> HOST: {}, PORT: {}", host, port);
return false;
@saniaky
saniaky / Readme.md
Last active October 30, 2024 15:30
Docker + nginx-proxy + let's encrypt + watchtower + fail2ban

Complete solution for websites hosting

This gist contains example of how you can configure nginx reverse-proxy with autmatic container discovery, SSL certificates generation (using Let's Encrypt) and auto updates.

Features:

  • Automatically detect new containers and reconfigure nginx reverse-proxy
  • Automatically generate/update SSL certificates for all specified containers.
  • Watch for new docker images and update them.
  • Ban bots and hackers who are trying to bruteforce your website or do anything suspicious.
@saniaky
saniaky / README.md
Last active April 9, 2019 07:05
Automatic backup of all MySQL databases to AWS S3 + restore script that downloads latest backup and imports it
  1. Create S3 bucket db-backup
  2. Specify Expire Policty to remove old backups
    Open Bucket Settings -> Management -> Add lifecycle rule -> Expiration tab
    Select Expire current version of object. Use 30 days.
    Select Permanently delete previous versions. Use 1 day.
  3. Create user db-backup-user, assign inline permission policy:
    {
        "Version": "2012-10-17",
    

"Statement": [

@saniaky
saniaky / aws-s3-policy.json
Last active January 14, 2022 01:06
Backup and restore a ALL MySQL databases from a running Docker MySQL container.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowPolicy",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:ListBucket"
@saniaky
saniaky / custom_proxy_settings.conf
Last active August 15, 2023 09:05
Docker + Wordpress + Nginx Proxy + Let's encrypt + Watcher
client_max_body_size 64m;
@saniaky
saniaky / instructions.txt
Last active December 1, 2018 18:02
Initial Server Setup CentOS + Docker
# ============ Create separate user ============
https://www.digitalocean.com/community/tutorials/initial-server-setup-with-centos-7
https://www.digitalocean.com/community/tutorials/how-to-create-a-sudo-user-on-centos-quickstart
local$ ssh root@server_ip_address
# adduser username
# passwd username
# usermod -aG wheel username
# ============ Copy your SSH key to server ============
@saniaky
saniaky / package.json
Last active February 16, 2021 10:52
Reverse proxy server for API + create-react-app (CRA)
{
"name": "test",
"version": "0.1.0",
"private": true,
"scripts": {
"app": "concurrently \"node proxy-middleware.js\" \"npm start\"",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
@saniaky
saniaky / Messages.java
Created December 5, 2017 11:10
Example of using message resources in Spring Boot service layer code, in as simple way.
import org.springframework.context.MessageSource;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.stereotype.Component;
import java.util.Locale;
/**
* @author saniaky
* @since 12/5/17
*/
@saniaky
saniaky / TokenController.java
Last active February 3, 2021 15:53
How to logout (revoke token + refresh token) user in Spring Security using OAuth 2.0
@Controller
public class TokenController {
private final TokenStore tokenStore;
@Autowired
public TokenController(TokenStore tokenStore) {
this.tokenStore = tokenStore;
}
@saniaky
saniaky / gist:7acfeb88746e4d6acc7624d3c5f50886
Last active November 28, 2017 14:01
Create MySQL database in utf8
=======> Create database
CREATE DATABASE db_name CHARACTER SET utf8 COLLATE utf8_general_ci;