我正在为我的 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;
}
关于javascript - 如何在 nginx 后面设置 Phantomjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20826327/