init
This commit is contained in:
		
							
								
								
									
										13
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					FROM debian:stable-slim
 | 
				
			||||||
 | 
					COPY wstunnel.conf /etc/nginx/conf.d/
 | 
				
			||||||
 | 
					COPY entrypoint.sh /usr/local/bin/entrypoint.sh
 | 
				
			||||||
 | 
					RUN chmod +x /usr/local/bin/entrypoint.sh \
 | 
				
			||||||
 | 
					    && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y wget nginx \
 | 
				
			||||||
 | 
					    && wget -O /usr/local/bin/wstunnel \
 | 
				
			||||||
 | 
					    https://github.com/erebe/wstunnel/releases/download/v5.0/wstunnel-linux-x64 \
 | 
				
			||||||
 | 
					    && chmod +x /usr/local/bin/wstunnel \
 | 
				
			||||||
 | 
					    && rm -vf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
 | 
				
			||||||
 | 
					ENV WS_PATH_PREFIX=${WS_PATH_PREFIX:-}
 | 
				
			||||||
 | 
					ENV SERVER_HOST=${SERVER_HOST:-localhost}
 | 
				
			||||||
 | 
					ENV SERVER_PORT=${SERVER_PORT:-8080}
 | 
				
			||||||
 | 
					ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
 | 
				
			||||||
							
								
								
									
										30
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
				
			|||||||
 | 
					# wstunnel with Nginx
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[wstunnel](https://github.com/erebe/wstunnel) with nginx as reverse proxy.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Run server:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					docker run -d \
 | 
				
			||||||
 | 
					    --name wstunnel \
 | 
				
			||||||
 | 
					    -p 8080:80 \
 | 
				
			||||||
 | 
					    -e SERVER_PORT=8080 \
 | 
				
			||||||
 | 
					    -e WS_PATH_PREFIX=md77sthqtq-o_ptobrd65n0ol56fk5bz \
 | 
				
			||||||
 | 
					    nxhs/wstunnel
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Connect:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					wstunnel --upgradePathPrefix md77sthqtq-o_ptobrd65n0ol56fk5bz -D 1080 ws://localhost:8080
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Environment:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					| Variable | Default | Description |
 | 
				
			||||||
 | 
					| --- | --- | --- |
 | 
				
			||||||
 | 
					| `SERVER_PORT` | Empty | Port what you want to publish |
 | 
				
			||||||
 | 
					| `SERVER_HOST` | localhost | Your server IP or domain name |
 | 
				
			||||||
 | 
					| `WS_PATH_PREFIX` | Random | Path prefix for websocket. Used as shared secret |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					See `docker logs wstunnel` to view generated client connection command.
 | 
				
			||||||
							
								
								
									
										17
									
								
								entrypoint.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								entrypoint.sh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					#!/bin/bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[ -n "$WS_PATH_PREFIX" ] || WS_PATH_PREFIX="$(< /dev/urandom tr -dc 'a-z0-9\-_' | head -c32)"
 | 
				
			||||||
 | 
					sed -i /etc/nginx/conf.d/wstunnel.conf -e "s/{{ws_path_prefix}}/$WS_PATH_PREFIX/"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cat << EOF
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Client connection command:
 | 
				
			||||||
 | 
					wstunnel --upgradePathPrefix $WS_PATH_PREFIX -D 1080 ws://$SERVER_HOST:$SERVER_PORT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					EOF
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					set -m
 | 
				
			||||||
 | 
					nginx -g "daemon off;" &
 | 
				
			||||||
 | 
					wstunnel --server ws://0.0.0.0:8080
 | 
				
			||||||
							
								
								
									
										13
									
								
								wstunnel.conf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								wstunnel.conf
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					server {
 | 
				
			||||||
 | 
					    listen 80 default_server;
 | 
				
			||||||
 | 
					    server_name _;
 | 
				
			||||||
 | 
					    location / {
 | 
				
			||||||
 | 
					        return 404;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    location /{{ws_path_prefix}}/ {
 | 
				
			||||||
 | 
					        proxy_pass http://127.0.0.1:8080;
 | 
				
			||||||
 | 
					        proxy_http_version 1.1;
 | 
				
			||||||
 | 
					        proxy_set_header Upgrade $http_upgrade;
 | 
				
			||||||
 | 
					        proxy_set_header Connection "upgrade";
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user