node.js - Node.js (express) 上的 Alexa Skill Server 使用 nginx 作为反向代理 (https)

标签 node.js express nginx reverse-proxy alexa

我正在我的 Debian 8.5 64bit 上运行 nginx,它用作我的 Node 应用程序的反向代理。每个请求在路由到特殊应用程序之前都会经过我的反向代理。因此我使用这个配置:

upstream socket_nodes {
  server 127.0.0.1:3000;
  server myUrl.com:3000;
  server MY.ROOTSERVER.IP.ADDRESS:3000;
}
server {
  listen 80 default_server;
  listen [::]:80 default_server;
  server_name myUrl.com;
  return 301 https://$server_name$request_uri;
}

server {
  # SSL configuration
  #
  listen 443 ssl default_server;
  listen [::]:443 ssl default_server;
  include snippets/ssl-my-website.com.conf;
  include snippets/ssl-params.conf; 

  # Self signed certs generated by the ssl-cert package
  # Don't use them in a production server!
  #
  # include snippets/snakeoil.conf;

  # Add index.php to the list if you are using PHP
  index index.html index.htm index.nginx-debian.html;

  server_name www.myWebsite.com;
  root /root/webserver/app/;
    location ~ /.well-known {
            allow all;
    }
  location / {
     proxy_pass http://localhost:8080;
         proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection 'upgrade';
         proxy_set_header Host $host;
         proxy_cache_bypass $http_upgrade;
  }
    location /alexa-api/ {
     proxy_pass http://localhost:3000;
  }
  location /at_backend/ {
    proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://socket_nodes;
  }


  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  #
  #location ~ \.php$ {
  # include snippets/fastcgi-php.conf;
  #
  # # With php5-cgi alone:
  # fastcgi_pass 127.0.0.1:9000;
  # # With php5-fpm:
  # fastcgi_pass unix:/var/run/php5-fpm.sock;
  #}

  # deny access to .htaccess files, if Apache's document root
  # concurs with nginx's one
  #
  #location ~ /\.ht {
  # deny all;
  #}
}

遗憾的是,这不起作用。我可以通过 https ( https://www.myWebsite.com ) 访问我的网站,并且工作正常。

因此,我将 Amazon 开发者控制台 中的 Alexa Skill 端点更改为:https://www.myWebsite.com/alexa-api(有或没有尾随 /) 但它不起作用。当我在本地使用技能服务器并通过 ngrok 使其可用时,技能服务器本身就可以工作。我在这里做错了什么?

编辑:

还有一个在同一个应用程序中运行的 socket.io 服务器,可以从互联网访问该服务器(服务器记录“新客户端已连接”) - 但我无法在它们之间发出任何事件。 socket.io 连接的 HTTP 状态代码(正确)是 101 Switching Protocols

问候

最佳答案

当您有 HTTPS 时,您还应该传递 https 方案

proxy_pass https://socket_nodes;

关于node.js - Node.js (express) 上的 Alexa Skill Server 使用 nginx 作为反向代理 (https),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49210006/

相关文章:

performance - 如何使用 Memcached 配置 NGINX 以提供 HTML

node.js - jhipster 不是内部或外部命令,也不是可运行的程序或批处理文件

javascript - Redis ReJSON 系统地返回两个错误 : missing key at non-terminal path and new object must be created at root

javascript - Handlebars.js - 循环一个不包括第一个元素的数组?

node.js - nginx : redirect to port according to domain prefix (dynamically)

负载均衡 Nginx 服务器上的 SSL

javascript - 无法在 node-cron 调度方法中获取数据

javascript - 如何在 V8 中将对象传递给 JavaScript 回调

mysql - Sequelize : How to make use of multiple operators to create a fetch of objects with an exclusion clause

javascript - 有没有更好的方法来处理 Node.js/Expressjs 中的嵌套回调?