webssh icon indicating copy to clipboard operation
webssh copied to clipboard

无法实现nginx的反向代理

Open superglg738 opened this issue 2 years ago • 3 comments

webssh写的静态文件 引用是用绝对路径。 nginx没法配置反向代理

static 可能在多个平台上被引用,又不能直接在写/static跳转。

go程序没整过,可以重新打包一个,采用相对路径的吗?

python也有一个webssh,也是用websocket传递的,可以配置在nginx后, 但是它没有文件上传功能

superglg738 avatar Apr 27 '23 01:04 superglg738

https://pypi.org/project/webssh/

+---------+ http +--------+ ssh +-----------+ | browser | <==========> | webssh | <=======> | ssh server| +---------+ websocket +--------+ ssh +-----------+

Nginx config example

location / { proxy_pass http://127.0.0.1:8888; proxy_http_version 1.1; proxy_read_timeout 300; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-PORT $remote_port; }

superglg738 avatar Apr 28 '23 00:04 superglg738

老哥实现了nginx的反向代理了吗

dachun639 avatar Aug 07 '24 02:08 dachun639

可以先将/web/dist/index.html(需要先用npm把网页资源编译好才会有)中引用的css和js等全部改为相对路径,如href="/static/xxx"改为href="./static/xxx",然后使用nginx配置地址转发,我用的url前缀是/jrohywebssh/,配置如下,实测命令行和文件上传下载都没问题。

`

map $http_upgrade $connection_upgrade {
    default        keep-alive;
    'websocket'    upgrade;
}

server {
    # 一些基本配置
    ...

    # jrohy-webssh
    location /jrohywebssh/ {
        proxy_pass http://127.0.0.1:5032/;
        proxy_http_version 1.1;
        proxy_read_timeout 300;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
    location /term {
        proxy_pass http://127.0.0.1:5032/term;
        proxy_http_version 1.1;
        proxy_read_timeout 300;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
    location /check {
        proxy_pass http://127.0.0.1:5032/check;
        proxy_http_version 1.1;
        proxy_read_timeout 300;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
    location /file {
        proxy_pass http://127.0.0.1:5032/file;
        proxy_http_version 1.1;
        proxy_read_timeout 300;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
    location /jrohywebssh {
        rewrite ^/(.*)$ http://xxxx.xxxx.xxxx/$1/ permanent;
    }

}

`

santiaosanren avatar Sep 10 '24 08:09 santiaosanren