I am using prerender.io to make my AngularJS website crawlable.
However, since I started using prerender.io, the majority of my CRUD requests (e.g. update, delete) return an nginx 405 Not Allowed response.
Original (working) nginx location block (before using prerender.io):
location / {
try_files $uri $uri/ /index.php?$query_string;
}
Current location block (Fetch as Google correctly displays static html, CRUD does not work):
location / {
try_files $uri @prerender;
}
Current prerender block
location @prerender {
proxy_set_header X-Prerender-Token D3Ft1yU7Ho3nNMwvgQQO;
set $prerender 0;
if ($http_user_agent ~* "baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator") {
set $prerender 1;
}
if ($args ~ "_escaped_fragment_") {
set $prerender 1;
}
if ($http_user_agent ~ "Prerender") {
set $prerender 0;
}
if ($uri ~ "\.(js|css|xml|less|png|jpg|jpeg|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpg|mpeg|tif|wav|mov|psd|ai|xls|mp4|m4a|swf|dat|dmg|iso|flv|m4v|torrent|ttf|woff)") {
set $prerender 0;
}
resolver 8.8.8.8;
if ($prerender = 1) {
set $prerender "service.prerender.io";
rewrite .* /$scheme://$host$request_uri? break;
proxy_pass http://$prerender;
}
if ($prerender = 0) {
rewrite .* / break;
}
}
I believe that the problem is caused either by my current location block or my rewrite statement.
I tried several alternatives for both. e.g.:
#CRUD works, FETCH as google does not work
try_files $uri $uri/ @prerender /index.php?$query_string;
#CRUD works, FETCH as google does not work
try_files $uri @prerender $uri/ /index.php?$query_string;
#CRUD does not work, FETCH does work
try_files $uri $uri/ /index.php?$query_string @prerender;
rewrite .* /index.html break;
rewrite .* /?$query_string break;
rewrite .* /index.php?$query_string break;
etc.
However, in all these configurations EITHER crud works OR prerendering the HTML correctly, never both. Any ideas how I can fix this?
Surprisingly, after the latest Ubuntu update, the last rewrite mentioned in my question (rewrite .* /index.php?$query_string;) did the trick. I am not sure why.