无法实现nginx的反向代理
webssh写的静态文件 引用是用绝对路径。 nginx没法配置反向代理
static 可能在多个平台上被引用,又不能直接在写/static跳转。
go程序没整过,可以重新打包一个,采用相对路径的吗?
python也有一个webssh,也是用websocket传递的,可以配置在nginx后, 但是它没有文件上传功能
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; }
老哥实现了nginx的反向代理了吗
可以先将/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;
}
}
`