首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使rasa网络聊天与nginx和https一起工作?

如何使rasa网络聊天与nginx和https一起工作?
EN

Stack Overflow用户
提问于 2020-06-17 21:20:16
回答 1查看 1.1K关注 0票数 0

我有一个用rasa实现的聊天机器人,它正在与rasa 网上聊天一起工作。当我用ngrok在本地测试它时,它工作得很好,当我在服务器上配置nginx (端口80)时,它也可以工作。但是,当我更改nginx配置文件以支持https后,webchat只显示了“Connecting.”消息,没有响应。我在浏览器控制台中查找错误,但没有错误。这是我的索引文件,负责webchat界面:

代码语言:javascript
运行
复制
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Fe</title>
</head>

<body>
    <div id="webchat">
    <script src="https://storage.googleapis.com/mrbot-cdn/webchat-0.5.8.js"></script>
    <script>
        WebChat.default.init({
            selector: "#webchat",
            initPayload: "hi",
            interval: 1000,
            socketUrl: "https://example.com/rasa",
            socketPath: "/socket.io/",
            title: "speak with bot",
            inputTextFieldHint: "say something...",
            connectingText: "Connecting...",
            connectOn: open,
            embedded: true,
            hideWhenNotConnected: false,
            /*fullScreenMode: true,*/
            profileAvatar: "assets/fe.jpeg",
            openLauncherImage: 'assets/launcher_button.svg',
            closeLauncherImage: 'assets/launcher_button.svg',
            params: {
                images: {
                    dims: {
                        width: 300,
                        height: 200,
                    }
                },
                storage: "session"
            }
        })
    </script>
</body>

</html>

这是经过适当修改以支持https的nginx配置文件:

代码语言:javascript
运行
复制
upstream rasa {
        server bot-webchat:5005; # bot-webchat is the chatbot container name
}

server {
        listen 80;
        listen [::]:80;

        server_name example.com www.example.com;

        location ~ /.well-known/acme-challenge {
                allow all;
                root /var/www/html;
        }

        location / {
                rewrite ^ https://$host$request_uri? permanent;
        }
}

server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name example.com www.example.com;

        index index.php index.html index.htm;

        root /var/www/html;

        server_tokens off;

        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

        ssl on;
        ssl_session_cache  builtin:1000  shared:SSL:10m;
        ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
        ssl_prefer_server_ciphers on;

        location / {
                try_files $uri $uri/ =404;
        }

        # the next two location directives were necessary to avoid mixed content error and allow
        # https access to port 5005 and websocket
        location /rasa/ {
                proxy_pass http://rasa;
                proxy_http_version  1.1;
                proxy_set_header Upgrade           $http_upgrade;
                proxy_set_header Connection        "upgrade";
                proxy_set_header Host              $host;
        }

        location /socket.io/ {
                proxy_pass http://rasa/socket.io;
                proxy_http_version  1.1;
                proxy_set_header Upgrade           $http_upgrade;
                proxy_set_header Connection        "upgrade";
                proxy_set_header Host              $host;
        }

        location = /favicon.ico {
                log_not_found off; access_log off;
        }

        location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
                expires max;
                log_not_found off;
        }
}

经过我所做的测试,我相信我的nginx配置文件可能有问题,但我不知道这是什么.我还使用邮递员来验证"https://example.com/rasa“和"https://example.com/socket.io”是否按预期进行响应。如果有人能帮我弄清楚发生了什么,我会很感激的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-22 06:34:36

我的bot还构建了与您一样的rasa、僵尸/湿聊天和nginx。

webchat的机器人配置如下所示:

代码语言:javascript
运行
复制
WebChat.default.init({
  selector: '#webchat',
  profileAvatar: 'https://www.jrcg.vip/assets/images/bot_avatar.jpg',
  initPayload: '/greet',
  params: { storage: 'session' },
  customData: { language: 'zh' },
  socketUrl: 'https://www.jrcg.vip',
  socketPath: '/socket.io/',
  title: '五竹',
  subtitle: '蠢萌蠢萌的机器人',
  inputTextFieldHint: '对我说点什么吧'
});

在nginx配置中的配置是:

代码语言:javascript
运行
复制
# ...

location /socket.io/ {
        proxy_pass http://127.0.0.1:5005;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header X-real-ip $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
}

# ...

您可以将location /rasa/location /socket.io/合并到一个位置。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62438555

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档