Page 416 - AngularJS权威教程
P. 416

396  第 30 章  AngularJS 和 IE 浏览器


                 然后需要重新载入Apache配置:

                 $ sudo /etc/init.d/apache2 reload
                 可以在站点的虚拟主机配置中,或者位于服务器根目录的.htaccess文件中设置重写规则。
                 RewriteEngine On
                 Options +FollowSymLinks
                 RewriteCond %{REQUEST_URI} ^/$
                 RewriteCond %{QUERY_STRING} ^_escaped_fragment_/?(.*)$
                 RewriteRule ^(.*)$ /snapshots/%1? [NC,L]

             30.5.3 使用Ngnix代理URL

                              ①
                 如果使用Nginx 为Angular应用提供服务,并且在查询字符串中有一个_escaped_fragment_
             参数,那么也可以添加一些配置以便提供应用的快照。
                 和Apache不同,Nginx无需启用什么模块,因此可以简单地更新配置来处理替换文件路径的
             问题。

                 在Nginx配置文件中(比如/etc/nginx/nginx.conf),需要确保配置信息看起来像这样:

                 server {
                     listen: 80;
                     server_name example;

                     if($args ~ "_escaped_fragment_=/?(.+)") {
                         set $path $1;
                         rewrite ^ /snapshots/$path last;
                     }

                     location / {
                         root /web/example/current/;
                         # Comment out if using hash urls
                         if(!-e $request_filename) {
                             rewrite ^(.*)$ /index.html break;
                         }
                         index index.html;
                     }
                 }
                 这一步完成之后就可以重新加载配置信息了:

                 sudo /etc/init.d/nginx reload
             30.6 获取快照


                 我们可以使用PhantomJS 或者zombie.js 等工具来渲染页面,以便提供后台应用的HTML快
                                                   ③
                                      ②
             照。当Google使用_escaped_fragment_查询参数请求一个页面时,我们就可以简单地返回并渲
             染这个页面。

             ——————————
                ① http://wiki.nginx.org/Main
                ② http://phantomjs.org/
                ③ http://zombie.labnotes.org/
   411   412   413   414   415   416   417   418   419   420   421