CentOS安装WebSSH并代理到nginx

1.安装依赖

1.1安装python3

[root@zyxfx ~]# yum -y install python3

检查python3是否安装成功

[root@zyxfx ~]# python3 -V 
Python 3.6.8

1.2安装pip

安装epel扩展源

[root@zyxfx ~]# yum -y install epel-release

安装pip

[root@zyxfx ~]# yum -y install python-pip

2.获取webssh程序包

下载源码:github.com

[root@zyxfx ~]#cd /data
[root@zyxfx ~]#-rw-r--r--.  1 root root 337828 Oct 23 09:13 webssh-master.zip
[root@zyxfx ~]# unzip webssh-master.zip
[root@zyxfx ~]# mv webssh-master webssh

3.安装

进入webssh目录安装webssh

[root@zyxfx ~]# cd webssh
[root@zyxfx ~]# python setup.py install

启动wssh

[root@zyxfx ~]# wssh

如果访问出现403是因为webssh对http进行了拦截

error:webssh Public plain http request is forbidden.

根据GitHub作者提供的解决方案,开放普通http就可以了:

[root@zyxfx ~]# wssh --fbidhttp=False

后台运行

[root@zyxfx ~]# wssh &

4.使用系统service管理

创建webssh.service文件

[root@zyxfx ~]# cat /etc/systemd/system/webssh.service
[Unit]
Description=webssh service
After=network.target

[Service]
Type=simple
EnvironmentFile=/usr/bin/python3
ExecStart=/usr/local/bin/wssh 
ExecReload=/bin/kill -HUP $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
[root@zyxfx ~]# systemctl daemon-reload

先停止webssh

[root@zyxfx ~]# ps -ef |grep wssh
root       826     1  0 09:37 ?        00:00:01 /usr/bin/python3 /usr/local/bin/wssh
root      6465  2428  0 10:09 pts/0    00:00:00 grep --color=auto wssh
[root@zyxfx ~]# kill -9 826 

使用系统systemctl启动webssh

[root@zyxfx ~]# systemctl srart webssh.service #启动
[root@zyxfx ~]# systemctl stop webssh.service #停止
[root@zyxfx ~]# systemctl restart webssh.service #重启
[root@zyxfx ~]# systemctl enable webssh.service #开机自启
[root@zyxfx ~]# systemctl status webssh.service #查看状态
● webssh.service - webssh service
   Loaded: loaded (/etc/systemd/system/webssh.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2023-10-23 09:37:49 CST; 35min ago
 Main PID: 826 (wssh)
   CGroup: /system.slice/webssh.service
           └─826 /usr/bin/python3 /usr/local/bin/wssh
......以下省略......

5.nginx代理

添加nginx配置到server中

server {
    location /webssh/ {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_read_timeout 1200s;
        proxy_send_timeout 1200s;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_redirect off;
        proxy_pass "http://127.0.0.1:8888/";
        proxy_http_version 1.1;
        #开启websocket
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        #白名单,允许某些IP访问
        #allow 192.168.19.206;
        #allow 192.168.19.12;
        #黑名单,禁止所有IP访问
        #deny all;
    }
}

6.访问

6.1使用wssh访问

web访问:http://ip:8888

6.2使用nginx访问

http://nginx_IP:nginx的端口/webssh
结果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值