如何为 Rasa 聊天机器人设置 HTTPS?

时间:2021-06-02 12:43:52

标签: nginx https socket.io rasa web-chat

我有一个在测试平台云服务器上运行的聊天机器人(5 个)。它们都在 HTTP 模式下完美运行,但我不需要更改为 HTTPS 模式,然后问题就开始了。我可以轻松地使 HTTPS 正常工作,但随后聊天机器人小部件不再工作。

我的环境:
聊天机器人引擎:Docker 20.10.6 容器中的 Rasa 2.2
聊天机器人小部件:Botfront webchat 0.11.12
网络服务器:Nginx 1.14.0
服务器:Ubuntu 18.04

我什至不知道什么是正确的方法,在敲了一个星期并尝试了不同的方法之后,现在我想我需要设置 Nginx 反向代理。我认为问题在于 rasa 和 webchat 之间的 websocket

这就是我如何开始一个聊天机器人

<块引用>

docker run --name=sakky --user 1003 -v $(pwd):/app -p "5006:5005" rasa/rasa:2.2.0-full run -m models --enable-api -- cors "*" --debug

这是我的配置文件 索引html

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <script src="https://cdn.jsdelivr.net/npm/rasa-webchat@0.11.12/lib/index.min.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
testi sakky
<div id="webchat"></div>
<script>
  WebChat.default.init({
    selector: "#webchat",
    initPayload: "/tervetuloa",
    customData: {"language": "fi"}, // arbitrary custom data. Stay minimal as this will be added to the socket
    socketUrl: "http://sakkybotti1.omnia.fi:5006",
    socketPath: "/socket.io/",
    embedded: false,
    title: "Sakky bot",
    subtitle: "Lisätietoja hakemisesta ja opiskelusta",
    inputTextFieldHint: "Kirjoita kysymys tähän",
    profileAvatar: "robot_icon.png",
    params: {"storage": "session"} // can be set to "local"  or "session". details in storage section.
  })
</script>

</body>
</html>

这里是 Nginx 配置文件,你可以看到我已经尝试了很多候选解决方案

#upstream rasa server {
#    server sakky:5006;
#}


server {
        listen 443 ssl;
        #listen [::]:443;
        #listen 444;

        #root /var/www/html/sakkyhttps;

        #index index.html index.htm index.nginx-debian.html;

        server_name sakkybotti1.omnia.fi;

        #return 301 https//:$host$request_uri;


        location / {
                #try_files $uri $uri/ =404;
                #proxy_pass http://sakkybotti1.omnia.fi;
                #proxy_set_header Host $host;
                root /var/www/html/sakkyhttps;
                index index.html;
                proxy_redirect https://sakkybotti1.omnia.fi http://sakkybotti1.omnia.fi;
                #proxy_redirect https://sakkybotti1.omnia.fi:5006/socket.io/ http://sakkybotti1.omnia.fi/;

                #proxy_pass http://sakkybotti1.omnia.fi/;
                #proxy_pass https://sakkybotti1.omnia.fi:5006/socket.io/ http://sakkybotti1.omnia.fi/;

                #proxy_pass http://sakkybotti1.omnia.fi;
                #proxy_http_version 1.1;
                #proxy_set_header Connection "upgrade";

                 #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                 #proxy_set_header Host $host;

                 #proxy_pass http://sakkybotti1.omnia.fi;

                 #proxy_http_version 1.1;
                 #proxy_set_header Upgrade $http_upgrade;
                 #proxy_set_header Connection "upgrade";


        }

   # listen [::]:443 ssl ipv6only=on; # managed by Certbot
    #listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/sakkybotti1.omnia.fi/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/sakkybotti1.omnia.fi/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}
#server {
#    if ($host = sakkybotti1.omnnia.fi:444) {
#        return 301 https://$host$request_uri;
#    } # managed by Certbot

  #listen 444 default_server;
  #listen 444
  #listen [::]:80 default_server;

#  server_name sakkybotti1.omnia.fi;
#    return 404; # managed by Certbot
#}

1 个答案:

答案 0 :(得分:0)

您是否可以至少更新到 Rasa 2.5?那个里面有一些 socket.io 修复!

您还需要确保configured your bot to have the websocket channel open