Forward requests in your nginx.conf file

Add the following directives to the server { ... } section of your nginx.conf file to forward snapshot requests. (Replace YOUR_API_KEY with your real API key that you got when signing up)

if ( $args ~ _escaped_fragment_ ) {
  rewrite ^(.*)$ /seojs-proxy$scheme://$host:$server_port$uri last;
}

location ^~ /seojs-proxy {
  proxy_pass http://cdn.getseojs.com/v2/YOUR_API_KEY/;
}

A complete example nginx.conf with the forwarding directives included:

server {
  listen   80;
  server_name  myserver;
  access_log  /var/log/nginx/myserver.access.log;

  if ( $args ~ _escaped_fragment_ ) {
    rewrite ^(.*)$ /seojs-proxy$scheme://$host:$server_port$uri last;
  }

  location ^~ /seojs-proxy {
    proxy_pass http://cdn.getseojs.com/v2/YOUR_API_KEY/;
  }

  location / {
    root   /srv/www/myserver/current/;
    # Uncomment the following 3 lines if you are using pushState URLs
    # if (!-e $request_filename){
    #   rewrite ^(.*)$ /index.html break;
    # }
    index  index.html index.htm index.php;
  }
}

Reload config

After completing these steps you’ll need to reload your Nginx config:

$ sudo /etc/init.d/nginx reload

Enable AJAX crawling

To tell search engine crawlers that your site allows AJAX crawling you need to add the fragment meta tag to your HTML header.

<head>
  <meta name="fragment" content="!">
  ...
</head>

Use compatible URLs

Your URLs need to be in one of these formats:

  • /nice#!page - they are Hashbang URLs
  • /nice/page - they are HTML5 PushState URLs

Hashbang URLs are easier to implement and are compatible with older browsers, but many users find PushState URLs look more convenient.

Hash fragment URLs without the exclamation mark cannot be crawled:

  • /one#page needs to be changed to /one#!page or /one/page