Saturday, August 13, 2011

SSH Tunnelling + SOCKS Proxy browsing

This is the simplest way to access content not available in your country. For example, if you want to access from Canada, you may use this method.

First of all, you need a server running Linux in the US.  You may either have a dedicated server or virtual dedicated server, or your home computer in the US.

From your client side, you need to issue 'ssh -D 9999 user@your_server_ip', so that to create a tunnel from your client to the server.

Then, in your browser, you just need to set the proxy to 'localhost:9999' so you can access content in the US with a US IP address, aka your server's ip.

This is the simplest way to access content outside of US.


Wednesday, July 27, 2011

tmux vs. screen

I am an experienced GNU screen users for many years.  Recently, I learned to use tmux and found it is a great replacement of screen.

Tmux is originally developed in OpenBSD and was ported to many systems.

The configuration is easy with many configurable options. Here is my startup script of tmux.


# basic setup
export LD_LIBRARY_PATH=/home/me/lib

# session related setup


if [ "$ENV" = "" ]; then

$TMUX start-server
$TMUX new-session -d -s leo '/bin/bash'
$TMUX new-window -t leo:1 '/bin/bash'
$TMUX new-window -t leo:2 '/bin/bash'

case $ENV in
        $TMUX send-keys -t leo:0 'cd; ls -lrt' C-m
        $TMUX send-keys -t leo:0 "cd $ENGWEB; vim s.cgi" C-m
        $TMUX send-keys -t leo:1 "cd $LIBPERL; vim" C-m
        $TMUX send-keys -t leo:2 "cd $ENGWEB; ls -l" C-m
        $TMUX send-keys -t leo:0 "cd $HOME; ls -l" C-m
        $TMUX send-keys -t leo:1 "cd $HOME/bin; ls -l" C-m
        $TMUX send-keys -t leo:2 "cd $HOME/stats; ls -l" C-m


$TMUX select-window -t leo:0
$TMUX attach-session -t leo

my .tmux.conf file

# Reload key
bind r source-file ~/.tmux.conf

# vim: foldmethod=marker

# {{{1 global options                                                                                                                                                                                                                                                                  
# redefine the prefix key
set -g prefix C-a
unbind C-b
bind a send-prefix

# }}}1

# {{{1 key bindings
bind C-o last-window

bind -r k select-pane -U
bind -r j select-pane -D
bind -r h select-pane -L
bind -r l select-pane -R

bind -r = resize-pane -U 3
bind -r - resize-pane -D 3

#bind -r C-k rotate-window -U 
#bind -r C-j rotate-window -D
bind -r C-k swap-pane -U 
bind -r C-j swap-pane -D

# bind -r C-n next-window
# bind -r C-p previous-window

bind -r y next-layout
bind o select-layout "active-only"
bind O select-layout "main-vertical"

bind '"' choose-window
bind - split-window -v
bind | split-window -h

bind q kill-pane
bind Q kill-window

bind A command-prompt "rename-window %%"

bind-key -n C-n new-window -n bash '/bin/bash'
bind-key -n C-b next-window
bind-key -n C-v previous-window


# {{{1 window options 
# disable automatic window renaming
setw -g automatic-rename off

# enable utf8 
setw -g utf8 on

setw -g xterm-keys on

# use vi mode in scroll mode and paste mode
setw -g mode-keys vi

# }}}1

# {{{1 status bar
set -g status-bg white
set -g status-fg black
set -g status-interval 60
set -g status-left-length 30
set -g status-left '#[fg=blue](#S) #(whoami)@#H#[default]'
set -g status-right '%a %m/%d %H:%M'
set-window-option -g window-status-current-bg yellow

# }}}1

set -g default-terminal "xterm-256color"
set -g history-limit 1000

# Set window notifications
setw -g monitor-activity on
set -g visual-activity on

# Automatically set window title
setw -g automatic-rename                                                                                                                                                                                                                                                               

Monday, May 09, 2011

nginx and daemontools

To use nginx with daemontools, the following configuration variable has to be set in your nginx.conf.

daemon off;

The following is the simple /service/nginx/run script to use with daemontools.


exec fghack /usr/sbin/nginx

To get your php-cgi working with nginx, you'd use spawn-fcgi, which is a tool spinned-off from lighttpd.

The /service/php-cgi/run script


exec /usr/bin/spawn-fcgi -n -p 9999 -a -u nginx -g nginx -- /usr/bin/php-cgi