【问题标题】:Sendgrid brand link with nginx proxySendgrid 品牌链接与 nginx 代理
【发布时间】:2018-08-28 07:43:34
【问题描述】:

我们尝试使用此文档https://sendgrid.com/docs/ui/account-and-settings/custom-ssl-configurations/ 设置带有自定义 ssl 的品牌链接。

我们关注它,现在我们有一个带有证书的代理,它重定向到 sendgrid.net。

支持人员告诉我们,他们的测试显示“失败:我们没有从测试‘https’点击跟踪链接得到 200 响应。”并告诉我们不支持代理上的证书通配符。

我不明白通配符的原因,代理发送的不是200,因为sendgrid.net发送的是404

所以我不明白该怎么做。

我们使用 nginx 和这个例子来实现我们的代理:https://gist.github.com/jjhiew/cbbd26da313fc550467e303a6c6f8177

【问题讨论】:

  • 我在使用 SendGrid 时遇到了同样的问题。我认为他们的支持人员不了解自定义 SSL 配置。他们的支持人员似乎与他们自己的文档相矛盾。我知道了,我会在这里发布。
  • @Winston 有什么更新吗?

标签: nginx proxy sendgrid


【解决方案1】:

感谢您的提醒。我们确实有它的工作,但我忘了把它贴在这里。总体思路是 有品牌点击请求转到我们自己的服务器,该服务器具有 TLS 证书。 IE。链接.mysite.com 转到我们自己的服务器而不是 SendGrid。我们的服务器接受这些请求,做出相同的 对 SendGrid 的请求。无论 SendGrid 向我们的服务器回复什么,我们都会将其发送回浏览器。

我不确定,但我认为 SendGrid 支持人员必须切换一些开关。但这可能是错误的。我记得我和他们谈过,我记得他们不理解这种代理情况。我是否终于找到了一个这样做的人,或者没有他们我是否可以工作,我不确定。

以下是我们为此使用的代码(Ruby on Rails):

# Allow SendGrid Click Tracking to use HTTPS
#
# SendGrid click tracking uses the host 'link.example.com' but HSTS requires that host
# respond to HTTPS. However SendGrid does not have our certificate. So instead point
# link.example.com to this proxy, and we make the same request to sendgrid.
#
# see: https://sendgrid.com/docs/ui/account-and-settings/custom-ssl-configurations/
#
# Configuring SendGrid, Heroku, and DNSimple for Click Tracking and unsubscribes
# ------------------------------------------------------------------------------
#   Sendgrid > Sender Authentication > Link Branding
#     Create branded link for example.com
#     Advanced Settings > Custom link subdomain: link
#
#   DNS > make the CNAME records they mention
#   Sendgrid >
#     verify branded links so they are activated.
#     Make link the default.
#
#   Heroku > configure subdomain for link.example.com
#   DNS > change CNAME record so link.example.com points to Heroku, e.g. blah.blah.herokudns.com
#
#   Test:
#       Unsubscribe links that start with link.example.com/___ should work now.
#
#   Sendgrid > Tracking > Click Tracking > ON
#
#   Test:
#     Send a test Frisky Friday.
#     Follow link to article--it should start with link.example.com
#     SendGrid increments the Click Tracking counter
class SendgridLinkProxyController < ActionController::Base
  SENDGRID_CLICK_TRACKING_URL = 'https://sendgrid.net'.freeze

  def index
    # Make matching request to SendGrid
    sendgrid_url = URI.parse("#{SENDGRID_CLICK_TRACKING_URL}#{request.env['ORIGINAL_FULLPATH']}").to_s
    sendgrid_headers = { 'Host' => CFG.SENDGRID_PROXY_HOSTNAME }

    Rails.logger.info("sendgrid_link_proxy_controller.rb: fetching #{sendgrid_url}, headers: #{sendgrid_headers}")
    sendgrid_response = HTTParty.get(sendgrid_url, headers: sendgrid_headers, follow_redirects: false) # , debug_output: STDOUT)

    # Make matching response to browser
    user_response_status = sendgrid_response.code
    response.set_header('location', sendgrid_response.headers['location'])
    Rails.logger.info("sendgrid_link_proxy_controller.rb: responding status_code: #{user_response_status}, location header: #{response.header['location']}")
    render html: sendgrid_response.body.html_safe, # We are trusting SendGrid. Winston think's that's OK. [Winston Dec 2018]
           status: user_response_status
  end
end

这里有一个 RSpec 文件:

require 'spec_helper'

describe SendgridLinkProxyController do

  describe '#index' do
    before do
      @sendgrid_response = {
        headers: {},
        body: '<html>SENDGRID BODY</html>',
        code: 200
      }
      request.env['ORIGINAL_FULLPATH'] = '/wf/click?upn=BLAH'
      CFG.SENDGRID_PROXY_HOSTNAME = 'link.example.com'
    end

    subject do
      allow(HTTParty)
        .to receive(:get)
        .and_return(double('Mock Sendgrid Response', @sendgrid_response))
      get :index, params: {a: 'click'}
    end

    it 'requests page from sendgrid with same path and with Host header' do
      expect(HTTParty).to receive(:get)
        .with('https://sendgrid.net/wf/click?upn=BLAH',
              headers: { 'Host' => 'link.example.com' },
              follow_redirects: false
             )

      subject
    end

    context 'when receiving a click-tracking redirect link' do
      before do
        @sendgrid_response[:code] = 302
        @sendgrid_response[:headers]['location'] = 'https://example.com/TARGET'
      end

      it 'redirects browser to target link' do
        subject

        expect(response.status).to eq(302)
        expect(response.headers['location']).to eq('https://example.com/TARGET')
      end
    end

    context 'when receiving an unsubcribe link' do
      before do
        request.env['ORIGINAL_FULLPATH'] = '/wf/unsubscribe?upn=BLAH'
      end

      it 'renders sendgrid\'s unsubscribe page' do
        subject

        expect(response.body).to eq('<html>SENDGRID BODY</html>')
      end
    end
  end
end

【讨论】:

    猜你喜欢
    • 2021-11-10
    • 2020-07-24
    • 1970-01-01
    • 2019-07-24
    • 2015-05-29
    • 1970-01-01
    • 2018-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多