javascript - 如何在 nginx 后面设置 Phantomjs

标签 javascript angularjs nginx phantomjs

我正在为我的 Angular 应用程序进行 SEO,当它是一个爬虫时,我正在使用 PhantomJS 来呈现 html。 出于某种原因,当我执行 http://aaaaa.com/?_escaped_fragment=/home 时,我得到了 501 但是当我执行 http://aaaaa.com

时,我得到了我的页面

这告诉我可能是 nginx 配置文件没有正确路由。

这是我的 nginx 配置(至少是片段):

  #mi angular app
        server {

                location / {

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

这是我用来运行 phantomjs 的命令:

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

当我运行它时,我得到:

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

所以 phantom 开始了,但是请求失败了……有什么想法吗?

最佳答案

这是我的配置:

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;
}

更多信息在这里:https://github.com/liuwenchao/ajax-seo

关于javascript - 如何在 nginx 后面设置 Phantomjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20826327/

相关文章:

javascript - 使用 jQuery Tabs 启用选项卡

javascript - Ajax 函数使用响应中的一些参数重新加载页面

angularjs - 客户端主机名被附加到客户端请求中

javascript - AngularJS 中未知数量输入的设置值

django - 使用 Nginx 为 Django 和 Vue 服务

Django 管理员不工作/丑陋 - 使用 nginx 和 Gunicorn 提供服务

php - 将数据从一个页面发送到另一台服务器。语言不可知论

javascript - 如何在脚本文件中使用 Laravel Blade?

javascript - 如何在 AngularJS 服务中添加到 $resource 的路由

Django REST AngularJS NGINX 配置