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

How to set up HTTPS for Rasa chatbot?

我在 testbed 云服务器上有一个聊天机器人(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
#}

您是否可以至少更新到 Rasa 2.5?其中有一些 socket.io 修复!

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