Skip to content

Instantly share code, notes, and snippets.

@dohsimpson
Last active November 7, 2018 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dohsimpson/b414ff7c460e15488def616242f7f0fa to your computer and use it in GitHub Desktop.
Save dohsimpson/b414ff7c460e15488def616242f7f0fa to your computer and use it in GitHub Desktop.
SA Application Guide

PostgreSQL

Create User

$ sudo -u postgres createuser -P cronly
$ sudo -u postgres psql
psql (10.5 (Ubuntu 10.5-2.pgdg16.04+1))
Type "help" for help.

postgres=# ALTER USER my_username WITH PASSWORD 'my_password';
ALTER ROLE
postgres=# ALTER USER my_username CREATEDB;
ALTER ROLE
postgres=# \q

Authentication password hashed

host    database          username          samenet         md5

Create DB

createdb -U my_username -h hostname database

Nginx

HTTP Reverse Proxy (credit)

conf.d/default.conf

upstream http_backend {
    server HOST_OR_IP:PORT;
}

server {
    listen       80;
    server_name  HOSTNAME;

    location /[PATH] {
        proxy_pass http://http_backend/;
    }
    ...
}

TCP Reverse Proxy (credit)

nginx.conf

...
stream {
    upstream tcp_backend {
        server HOST_OR_IP:PORT;
    }

    server {
        listen TCP_PORT;
        proxy_pass tcp_backend;
    }
}
...

Load Balance (credit)

*.conf

upstream backend {
    # round robin is default
    # least_conn;
    # hash $remote_addr;
    # random;
    
    server SERVER1:PORT [weight=5];
    server SERVER2:PORT [max_conns=3];
    server SERVER3:PORT [max_fails=2 fail_timeout=30s]; # passive health check
    ...
}

Two Servers

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/example.com/html;
    index index.html index.htm;

    server_name example.com www.example.com;

    location / {
        try_files $uri $uri/ =404;
    }
}

server {
    listen 80;
    listen [::]:80;

    root /var/www/test.com/html;
    index index.html index.htm;

    server_name test.com www.test.com;

    location / {
        try_files $uri $uri/ =404;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment