将请求重定向到https会中断Stripe webhook

时间:2014-08-17 06:53:20

标签: nginx stripe-payments

我最近修改了我的nginx服务器,将所有www.mysite个请求重定向到https://mysite

问题在于,当我这样做时,我设置的条带webhook现在因301重定向错误而失败。如何将我的nginx服务器更改为仅重定向来自我的域的请求? (或者至少我认为这是解决方案,我是一个前端人员。)

这是我的服务器。

server {
    listen 443;
    server_name mysite.com;
    root /var/www/mysite.com/app/mysite;

    ssl on;
    ssl_certificate /etc/nginx/ssl/cert.crt;
    ssl_certificate_key /etc/nginx/ssl/mykey.key;

    #enables SSLv3/TLSv1, but not SSLv2 which is weak and should no longer be used.
    ssl_protocols SSLv3 TLSv1;
    #Disables all weak ciphers
    ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;


    location / {
        proxy_pass        http://127.0.0.1:3000/;
        proxy_redirect    off;
        proxy_set_header  Host            $host;
        proxy_set_header  X-Real-IP        $remote_addr;
        proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
}

server {
  listen 80;
  server_name www.mysite.com;
  return 301 https://mysite.com$request_uri;
}

3 个答案:

答案 0 :(得分:4)

正如mpcabd所提到的,出于安全原因,Stripe webhooks不会遵循重定向。正如他所提到的,当你可以过滤IP时,它是一场永无止境的战斗(Stripe之前曾表示他们打算最终停止发布IP列表)。

更容易和更好的设置 - 忘记 - 解决方案:

Stripe dashboard中,重新配置您的webhook以使用HTTPS。

的Bam。完成。

答案 1 :(得分:2)

你可以做的是从重定向中排除Stripe,我认为他们的钩子不会出于安全原因而遵循重定向,这是公平的,所以试着看看他们使用什么IP,并确保你不重定向{ {1}}或$http_x_real_ip来自Strip的IP列表。

但正如Stripe明确指出的那样here

  

...因为我们偶尔需要调整此IP列表   地址没有任何提前通知,我们强烈建议反对   使用基于IP的访问控制来保护您的webhook端点。   相反,我们建议您通过SSL提供webhook端点,   在webhook URL中嵌入一个秘密标识符,该URL仅为其所知   你和Stripe,和/或从我们的API中通过ID检索事件......

所以我的答案是检查所请求的位置是否为Stripe webhook,然后在没有重定向的情况下提供,否则重定向请求

答案 2 :(得分:0)

请将中间证书与您签名的SSL证书连接。

参考: https://futurestud.io/tutorials/how-to-configure-nginx-ssl-certifcate-chain

相关问题