-
让一个端口同时做两件事:http/https和ssh
相信很多人都在YY:能不能让80端口分析连接协议,如果是http协议就让服务器交给http服务程序(如Apache、Nginx等)处理,如果是ssh协议就交给ssh服务程序(如OpenSSH Server)处理呢?
答案显然是有的。
首先,配置http服务程序监听8080端口或者让https服务监听8443端口,配置ssh服务程序监听22端口。具体不再赘述,如果这都不懂就不用往下看了,因为肯定会搞不定的。
然后,安装一个叫haproxy的强大工具。步骤如下。
下载源代码:
wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.16.tar.gz
查看当前内核版本:
uname -r
然后进入目录编译安装:
cd haproxy-1.4.16
make TARGET=linux26 PREFIX=/usr/local/blog.creke.net/haproxy
make install PREFIX=/usr/local/blog.creke.net/haproxy
其中,第二行的“TARGET”参数要和内核版本一致。第二、三行的“PREFIX”是安装位置。
最后,配置haproxy。
如果要监听80端口,检测到http协议就转发给8080端口使用HTTP,否则转发给22端口使用ssh。配置如下:
global
maxconn 5120
chroot /usr/local/blog.creke.net/haproxy
daemon
quiet
nbproc 2
pidfile /usr/local/blog.creke.net/haproxy/haproxy.piddefaults
timeout connect 5s
timeout client 50s
timeout server 20slisten http
bind :80
timeout client 1h
tcp-request inspect-delay 2s
acl is_http req_proto_http
tcp-request content accept if is_http
server server-http :8080
use_backend ssh if !is_httpbackend ssh
mode tcp
timeout server 1h
server server-ssh :22如果还有监听443端口,检测到https协议就转发到8443端口使用HTTPS,否则转发给22端口使用ssh。则配置如下:
global
maxconn 5120
chroot /usr/local/blog.creke.net/haproxy
daemon
quiet
nbproc 2
pidfile /usr/local/blog.creke.net/haproxy/haproxy.piddefaults
timeout connect 5s
timeout client 50s
timeout server 20slisten https
bind :443
timeout client 1h
tcp-request inspect-delay 2s
acl is_ssl req_ssl_ver 2:3.1
tcp-request content accept if is_ssl
server server-https :8443
use_backend ssh if !is_sslbackend ssh
mode tcp
timeout server 1h
server server-ssh :22把内容保存为“/usr/local/blog.creke.net/haproxy/etc/haproxy.conf”,执行命令:
/usr/local/blog.creke.net/haproxy/sbin/haproxy -f /usr/local/blog.creke.net/haproxy/etc/haproxy.conf
即可运行。
好了,大家应该可以举一反三,起码也可以依葫芦画瓢吧。
参考文章:
《让一个端口同时做两件事:http/https和ssh》已有 4 条评论
The trackbacks and pingpacks:
- 用ssh突破公司http代理 | 山羊博客 - Pingback on 12/11/23 12:37
最新文章
- EarthLiveSharp中cloudinary的CDN图片缓存自动清理
- WordPress取消英文标点符号自动替换中文标点符号的优雅方法
- 安装aria2及使用yaaw配置WebGUI界面
- Zabbix安装简记
- WordPress垃圾评论大作战
最近评论
- 发表在《64位Windows Server无法启动Tomcat服务的解决办法》
- 发表在《DNS隧道之DNS2TCP使用心得教程》
- 发表在《CentOS在SSH中运行GUI图形界面程序》
- 发表在《CentOS在SSH中运行GUI图形界面程序》
- 发表在《CentOS在SSH中运行GUI图形界面程序》
标签云
Apache
CCTV
CentOS
Google
JAVA
Linux
MySQL
PHP
PHPmyadmin
rewrite
SSH
StatusNet
wordpress
YY
下载
中国
使用
剧情
动漫
动漫补完计划
动画
博客
域名
安装
影评
恭贺2010
方法
日本
服务器
柯南
死亡笔记
游戏
电影
第10放映室
网站
网络
翻译
腾讯
观后感
规则
视频
解决
设置
评论
配置