William Falcon
William Falcon

Reputation: 9813

How to set up Phantomjs behind nginx

I'm working on SEO for my angular app and I'm using PhantomJS to render html when it is a crawler. For some reason I get a 501 when I do http://aaaaa.com/?_escaped_fragment=/home But I get my page when I do http://aaaaa.com

This tells me that it's probably by nginx config file that isn't routing properly.

Here is my nginx config (at least the snippet):

  #mi angular app
        server {

                location / {

                        if ($args ~ _escaped_fragment_) {
                                 proxy_pass http://localhost:8888;
                                 break;
                        }
                        root /var/www/html/miwebapp/client/app;
                }
        } 

Here is the command I use to run phantomjs:

phantomjs --disk-cache=no angular-seo-server.js 8888 http://localhost:8000/home

When I run it, I get:

Listening on 8888...
Press Ctrl+C to stop.

So phantom starts, but requests fail... Any thoughts?

Upvotes: 4

Views: 2128

Answers (1)

Louis
Louis

Reputation: 246

This is my configure:

if ($args ~ _escaped_fragment_) {
    rewrite ^ /snapshot$uri;
}

location ~ ^/snapshot(.*) {
    rewrite ^/snapshot(.*)$ $1 break;
    proxy_pass http://localhost:8888;
    proxy_set_header Host $host;
    proxy_connect_timeout 60s;
}

more info here: https://github.com/liuwenchao/ajax-seo

Upvotes: 2

Related Questions