I am having trouble configuring nginx to return the prerendered html when using HTTPS.
- nginx, prerender and my meteor app runs on the same server.
- prerender is in port 3033
- meteor app is in port 112
In meteor I have configured it to to point to the localhost:3033 for prerendering.
With the following no-SSL configuration, Facebook's tool is able to scrape my site successfully:
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;
}
}
However when I started using SSL Facebook is not able to scrape the site.
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;
}
One observation is that every time I run the FB tool with an HTTPS say https://sample.com/
, in prerender logs it says getting http://sample.com
(not HTTPS!).
Manually running a curl
command is successful
curl http://sample.com:3033/https://sample.com
Somewhere in between is clearly converting the protocol https
to http
.