Facebook 无法使用Nginx+;预渲染&x2B;流星

Facebook 无法使用Nginx+;预渲染&x2B;流星,facebook,meteor,nginx,prerender,Facebook,Meteor,Nginx,Prerender,我在配置nginx以在使用HTTPS时返回预呈现的html时遇到问题 nginx、prerender和my meteor应用程序在同一台服务器上运行 prerender位于端口3033中 meteor应用程序位于端口112 在meteor中,我将其配置为指向localhost:3033进行预渲染 通过以下无SSL配置,Facebook能够成功抓取我的网站: server { listen 80; server_name sample.com www.sample.com;

我在配置nginx以在使用HTTPS时返回预呈现的html时遇到问题

  • nginx、prerender和my meteor应用程序在同一台服务器上运行
  • prerender位于端口3033中
  • meteor应用程序位于端口112
在meteor中,我将其配置为指向localhost:3033进行预渲染

通过以下无SSL配置,Facebook能够成功抓取我的网站:

server {
    listen 80;
    server_name sample.com www.sample.com;

    # strip the "www" subdomain
    if ($host ~* ^www\.(.*)) {
        set $host_without_www $1;
        rewrite ^(.*) http://$host_without_www$1 permanent;
    }

    location / {
        # app is running in port 112 in the same server
        proxy_pass http://127.0.0.1:112;
        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;
    }
}
然而,当我开始使用SSL时,Facebook无法抓取该网站

server {
    listen 443 ssl;
    server_name sample.com www.sample.com;

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

    # strip the "www" subdomain
    if ($host ~* ^www\.(.*)) {
        set $host_without_www $1;
        rewrite ^(.*) http://$host_without_www$1 permanent;
    }

    location ~ /.well-known {
        allow all;
    }
    location / {
        # app is running in port 112 in the same server
        proxy_pass http://127.0.0.1:112;
        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;
    }
}
# redirect to https
server {
    listen 80;
    server_name sample.com www.sample.com;
    return 301 https://$host$request_uri;
}
一个观察结果是,每次我运行带有HTTPS的FB工具时,都会说
https://sample.com/
,在预渲染日志中,它表示获取
http://sample.com
不是HTTPS!

手动运行
curl
命令成功

curlhttp://sample.com:3033/https://sample.com


在这两者之间的某个地方显然正在将协议
https
转换为
http

听起来像是在负载平衡器或类似的地方终止SSL。在prerender配置中,将URL发送到prerender服务器时,您应该强制协议为https。

听起来像是在负载平衡器或类似设备上终止SSL。在prerender配置中,当将URL发送到prerender服务器时,您应该强制协议为https。

看来我的nginx配置还是不错的

我最终遵循了代码

  • 我从npm添加了预渲染节点

    meteor npm安装--保存预渲染节点

  • 我创建了/client/prerender-head.html

  • 我创建了/server/prerender.js

  • 注意我们强制协议为https的部分(类似于@Prerender.io建议的内容)

  • 已创建/settings.json
  • 将serviceUrl更改为运行prerender实例的位置

    {
      "PrerenderIO": {
          "serviceUrl": "http://localhost:3033/",
          "token": "yourtoken"
      }
    }
    
  • 使用meteor--settings.json运行应用程序

  • 看来我的nginx配置还是不错的

    我最终遵循了代码

  • 我从npm添加了预渲染节点

    meteor npm安装--保存预渲染节点

  • 我创建了/client/prerender-head.html

  • 我创建了/server/prerender.js

  • 注意我们强制协议为https的部分(类似于@Prerender.io建议的内容)

  • 已创建/settings.json
  • 将serviceUrl更改为运行prerender实例的位置

    {
      "PrerenderIO": {
          "serviceUrl": "http://localhost:3033/",
          "token": "yourtoken"
      }
    }
    
  • 使用meteor--settings.json运行应用程序

  • 您在预呈现内容的开放图形元标记中指定了什么
    og:url
    值?您在预呈现内容的开放图形元标记中指定了什么
    og:url
    值?谢谢您的回答。我能解决我的问题,就像你建议的一样。谢谢你的回答。我能像你建议的那样解决我的问题