Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

无法实现nginx的反向代理 #34

Open
superglg738 opened this issue Apr 27, 2023 · 3 comments
Open

无法实现nginx的反向代理 #34

superglg738 opened this issue Apr 27, 2023 · 3 comments

Comments

@superglg738
Copy link

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

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

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

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

@superglg738
Copy link
Author

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;
}

@dachun639
Copy link

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

@santiaosanren
Copy link

santiaosanren commented Sep 10, 2024

可以先将/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;
    }

}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants