微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

带有角度的 Unix 套接字的客户端

如何解决带有角度的 Unix 套接字的客户端

在 golang 中使用 unix 套接字创建服务器应用程序

服务器应用代码

package main
import (
  "fmt"
  "net"
  "net/http"
  "os"
)
func main() {
  sock := "/var/web.sock"
  err := os.Remove(sock)
  if err != nil {
    fmt.Printf("Can not remove socket config file.")
  }
  unixListener,err := net.Listen("unix",sock)
  if err != nil {
    fmt.Printf("Can not create unix socket listener,")
  }
  http.HandleFunc("/3dviewer/upload",uploadFile)
  http.Serve(unixListener,nil)
}
func uploadFile(w http.ResponseWriter,r *http.Request) {
   fmt.Printf("WORKING") 
}

需要客户端角度代码才能连接到服务器应用程序。请有人可以帮助我。

提前致谢

解决方法

可以使用Nginx等反向代理来处理Angular HTTP/HTTPS调用,并转发到Unix Socket

如果您使用 nginx,您可以在 /etc/nginx/site-available/your_configuration_file 处创建配置

然后启用它

sudo ln -s /etc/nginx/sites-available/your_configuration_file /etc/nginx/sites-enabled/

Nginx 配置文件示例

server {
    listen 80;
    server_name server_domain_or_IP;

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/myproject/myproject.sock;
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。