Code Monkey home page Code Monkey logo

Comments (10)

nirui avatar nirui commented on June 15, 2024

运行Sshwifty服务器端的计算机有图中所指的接口么?如果没有的话操作系统会拒绝程序的绑定申请。

你可以在服务器上运行命令 ip a | grep "这里填写IP地址"ifconfig | grep "这里填写IP地址" 来确认所填写的接口是存在的。

from sshwifty.

xingjiahui avatar xingjiahui commented on June 15, 2024

运行命令后无反应,那就应该是接口不存在。那我应该怎样做才能实现ip:端口访问?

from sshwifty.

nirui avatar nirui commented on June 15, 2024

那么你可以用ip a或者 ifconfig命令查看系统里存在的接口,然后找到WAN上可以访问的,绑定那一个就可以了。

或者如果对安全没有顾虑,可以绑定0.0.0.0,这样操作系统会自动绑定所有可用接口。

from sshwifty.

xingjiahui avatar xingjiahui commented on June 15, 2024

好的,感谢作者,解决了我的问题!

from sshwifty.

xingjiahui avatar xingjiahui commented on June 15, 2024

实在是打扰作者了,我又把这个issues打开了,我现在遇到的问题是使用ip:端口可以运行sshwifty,但我也想实现像您的demo那样可以直接使用域名访问(因为想https访问只能绑定域名),我尝试Nginx反代,但我不知道root该填写什么,下面是我的配置文件,希望您给个思路。

我是直接wget下载的release中linux的tar.gz包然后sshwifty运行的。

from sshwifty.

nirui avatar nirui commented on June 15, 2024

ListenInterface选项绑定的不是URL地址,而是本地网卡的IP地址。选项的值与实际访问的URL,比如https://10.0.0.1:8182并没有直接的对应关系。

root选项不是必须的。反向代理用proxy_这一系列选项就行了。可以参考下面的选项(你需要将一些设置改成适应自己运行环境的):

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

upstream sshwifty_backend {
    server 127.0.0.1:8182; # 这里改成你Sshwifty后端的地址以及其监听的端口
    server 127.0.0.2:8182; # 如果你有其他后端实例,可以填写多个来进行负载均衡
}

server {
    listen ..... # 服务器的设置,这里省略,用你自己的就好

    # 下面的Location设置会将浏览器的页面和相关资源请求转发给后端
    location / {
        proxy_pass http://sshwifty_backend;
        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 https;
    }

    # 下面的Location与上面的类似,不同之处是它会转发Websocket需要用到的Connection和Upgrade头,并且强制使用HTTP/1.1连接(不会进行HTTP/2握手)。
    location /sshwifty/socket {
        proxy_pass http://sshwifty_backend;
        proxy_http_version 1.1;
        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 https;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }
}

另外:

  1. 如果你在Sshwifty设置里指定了HostName,那么在反向代理的环境下就可以去掉了。因为Nginx会做相关的验证。
  2. 如果你的Nginx与Sshwifty是运行在同一台服务器上的,并且两个进程可以通过Loopback(127.0.0.1)接口进行网络通讯,那么现在你可以将Sshwifty的ListenInterface选项设置成127.0.0.1,让Sshwifty仅监听在Loopback上。这样可以确保只有本地进程才能连接Sshwifty后端,而外部客户端则需要通过Nginx的中转来进行访问(假定外部客户端能够访问Nginx。根据你给出的配置,我猜你大概是想要达成这样的目的)。

from sshwifty.

xingjiahui avatar xingjiahui commented on June 15, 2024

按照您给出的配置,我修改了nginx的配置信息,修改后使用ip:8182会出现下面的错误,也无法使用webssh.xingjiahui.top访问到Sshwifty,我也不清楚哪里出了问题,最终还是来请教作者了。




(我是小白,作者轻喷,哈哈,真的好想用自己的域名访问到自己服务器上的Sshwifty)

from sshwifty.

nirui avatar nirui commented on June 15, 2024

呵呵,这就是为什么我在 #21 (comment) 结尾的位置写了你可以去掉HostName设置里的东西。因为当HostName不为空时,Sshwifty会用其中的值来验证主机名。如果你访问的时候不是通过HostName中设定的主机名,则Sshwifty后端会拒绝你的访问。

另外,你需要将

listen ..... # 服务器的设置,这里省略,用你自己的就好

这一行改成你原先服务器的那几行配置,包括listen, server_namessl_之类。那一部分设置是不需要变更的,因此我在后面的答复里就没有引用了。

还有:

  1. 你应该在Sshwifty后端的配置里去掉TLS相关的设置,让Sshwifty运行在HTTP模式下。TLS这部分应该让Nginx去处理,就像你原先Nginx里写的配置一样。
  2. 如果你服务器的配置和条件许可的话,把Sshwifty的ListenInterface改成127.0.0.1可以避免潜在的安全问题。详情请看一下 #21 (comment)

简单的说,就是你最后配置成这样:

[你的浏览器] -------> [你服务器上的Nginx,HTTP/HTTPS] -------> [Sshwifty后端,HTTP]

from sshwifty.

nirui avatar nirui commented on June 15, 2024

另外,在你 #21 (comment) 给出的截图里,server 0.0.0.0:8182这个地址是不合法的。

如果你的Sshwifty实例与Nginx是运行在同一台服务器上的,并且可以通过127.0.0.1访问的话,填写server 127.0.0.1:8182就可以了。否则你的操作系统需要将0.0.0.0自动转换成127.0.0.1

from sshwifty.

xingjiahui avatar xingjiahui commented on June 15, 2024

好的,感谢作者的回复,我去尝试修改!

from sshwifty.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.