Skip to content

Instantly share code, notes, and snippets.

@schovi
Last active September 19, 2018 16:01
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 schovi/88b2d84666d64d97bb057b2d38d86abe to your computer and use it in GitHub Desktop.
Save schovi/88b2d84666d64d97bb057b2d38d86abe to your computer and use it in GitHub Desktop.
Simple personal ssh tunnel configuration. Require to have own domain and server with nginx.
user nobody nogroup;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
#default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name local.yourdomain.com *.local.yourdomain.com; # Or any domain you want to work
access_log /var/log/nginx/proxy.log;
error_log /var/log/nginx/proxy.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_pass http://127.0.0.1:9999;
}
}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
# Fish function to open proxy for you.
# Call as `proxy PORT_TO_TUNNEL`
function proxy
if count $argv > /dev/null
echo "Forwarding localhost:$1 to local.yourdomain.com:9999"
ssh root@local.yourdomain.com -R "9999:localhost:$argv[1]" "tail -fn 3 /var/log/nginx/proxy.log"
else
echo "No valid port passed as first argument"
end
end
# Open tunnel for given port and watch nginx proxy log to easily confirm what is coming thru.
ssh root@local.yourdomain.com -R "9999:localhost:PORT_TO_TUNNEL" "tail -fn 3 /var/log/nginx/proxy.log"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment