Skip to content

Instantly share code, notes, and snippets.

@trihtm
Last active December 16, 2016 14:28
Show Gist options
  • Save trihtm/f56f6da56033ae9a73dad7fc8b31bf59 to your computer and use it in GitHub Desktop.
Save trihtm/f56f6da56033ae9a73dad7fc8b31bf59 to your computer and use it in GitHub Desktop.
Server Stacks

Amazon AMI

Install NodeJS

sudo yum install nodejs npm --enablerepo=epel

http://stackoverflow.com/questions/27350634/how-to-yum-install-node-js-on-amazon-linux

Alpine Linux

A security-oriented, lightweight Linux distribution based on musl libc and busybox.

How to promote user

Because alpine is not built in usermod command. So we need to do the following trick:

deluser www-data
adduser -u 1000 -D -H www-data

Repository

https://pkgs.alpinelinux.org/packages

Docker Engine

Remove all stopped containers.

docker rm $(docker ps -a -q)

Remove all images

docker rmi $(docker images -q)

Docker Compose

Docker Machine

Refs:

https://docs.docker.com/compose/compose-file/

Nginx

General Tuning

nginx uses a fixed number of workers, each of which handles incoming requests. 
The general rule of thumb is that you should have one worker for each CPU-core your server contains.

Count CPUs available

grep ^processor /proc/cpuinfo | wc -l

Maximum number of connections = worker_processes * worker_connections

# One worker per CPU-core.
worker_processes

# Specifies how many connections each worker process can handle.
worker_connections

# Causes nginx to attempt to immediately accept as many connections as it can, subject to the kernel socket setup.
# Recommend to use epoll. Epoll event-model is generally recommended for best throughput.
multi_accept = epoll;

Remove server header on HTTP Request

server_tokens off;

Enable gzip - compression

Gzip involves the trade-off common to tuning, performing the compression takes CPU resources from your server, which frequently means that you'd be better off not enabling it at all. Generally the best approach with compression is to only enable it for large files, and to avoid compressing things that are unlikely to be reduced in size (such as images, executables, and similar binary files).

gzip  on;
gzip_vary on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";

Client caching

location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
     access_log        off;
     log_not_found     off;
     expires           30d;
}

Upstream

FastCGI

Refs:

http://nginx.org/en/docs/http/ngx_http_core_module.html

https://tweaked.io/guide/general/webservers/

http://nginx.org/en/docs/http/ngx_http_upstream_module.html

http://serverfault.com/questions/546349/what-is-the-difference-between-using-upstream-and-location-for-php-fpm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment