Archive for July 2015

tmux: a terminal multiplexer

tmux is a command-line tool that can create multiple virtual terminals in one terminal.



# on Ubuntu
$ sudo apt-get install tmux

# on macOS
$ brew install tmux

$ tmux -V
tmux 2.3


in ~/.tmux.conf

# prefix: Control + a
set -g prefix C-a

# kill-session: Control + a >> X
bind X confirm-before "kill-session -t ''"

# select-pane: Option + arrow key
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

# Start numbering at 1
set -g base-index 1
set-window-option -g pane-base-index 1

# Allows for faster key repetition
set -s escape-time 0

# Rather than constraining window size to the maximum size of any client
# connected to the *session*, constrain window size to the maximum size of any
# client connected to *that window*. Much more reasonable.
setw -g aggressive-resize on

set -g status-left-length 40

set -g mouse on

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

After adding new plugins, you need to press Control + A >> I to fetch and install them.



$ tmux
$ tmux new -s your_project

$ tmux ls

$ tmux attach
$ tmux attach -t your_project

# list all windows with their layouts
$ tmux list-windows

$ tmux kill-session -t your_project

# kill all sessions
$ tmux kill-server

# reload settings
$ tmux source ~/.tmux.conf
Control + a >> Shift + ?
list all shortcut keys

Control + a >> Shift + %
split window vertically

Control + a >> Shift + ""
split window horizontally

Control + a >> Arrow keys
Control + a >> q
move the cursor between panels

Control + a >> d

Control + a >> c
create a new window

Control + a >> p
switch to the previous window

Control + a >> n
switch to the next window

Control + a >> w
Control + a >> 0-9
switch to window 0-9

Control + a >> [
enable copy mode, you can use Option + Up or Option + Down to scroll

Control + a >> Shift + &
kill the current window

Control + a >> X
kill the current session




in ~/.tmuxinator/your_project.yaml

An example config:

# ~/.tmuxinator/dps.yml

name: dps
root: ~/Projects/dps

startup_window: django
startup_pane: shell

  - docker:
      layout: main-horizontal
        - up:
          - make up
  - django:
      layout: tiled
        - run:
          - make run
        - run_worker:
          - make run_worker
        - run_node:
          - make run_node
        - attach:
          - make attach
          - clear
$ tmuxinator start your_project



Control + a >> Control + s
save tmux env

Control + a >> Control + r
restore tmux env


Force HTTPS when using AWS ELB and nginx

You only have to setup the SSL certificate on Amazon ELB instead of every EC2 instance that behind ELB, normally you only receive HTTP traffic from Amazon ELB that serves both HTTP and HTTPS endpoints. The problem is that forcing HTTPS will result in a redirect loop when nginx only listens 80 port. A solution is forwarding HTTPS requests to another port, like 1443, in Amazon ELB.

Amazon ELB

Listeners configurations:

HTTP 80 >> HTTP 80
HTTPS 443 >> HTTP 1443

and health check target port should be HTTP:1443 instead of HTTP:80 or HTTPS:443.


in /etc/nginx/sites-available/your_website.conf

server {
    listen 80;
    rewrite ^ https://$host$request_uri? permanent;

server {
    listen 1443;