当我发现访问者是一个爬虫(给SEO优化的网站)和一个标准的php fast-cgi实例(通过fastcgi pass)时,我有一个特定的情况,我想将访问者redirect到“prerender”除此以外。
我对nginx的经验非常稀less,所以我无法完成我所需要的。
这是我当前configuration的草稿
server { server_name example.com; root /vagrant/example.com/web; index app.php; location /phpmyadmin { root /usr/share; index index.php; location ~* \.php { fastcgi_intercept_errors on; fastcgi_pass 127.0.0.1:9000; fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTPS off; } } location / { try_files $uri @rewriteapp; } location @rewriteapp { rewrite ^(.*)$ /app.php/$1 last; } location ~ ^/(app|app_dev)\.php(/|$) { #if $prerender is 1 should use the prerender proxy set $prerender 0; if ($http_user_agent ~* "googlebot|pinterest|vkshare|baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest|slackbot") { set $prerender 1; } if ($args ~ "_escaped_fragment_") { set $prerender 1; } if ($http_user_agent ~ "Prerender") { set $prerender 0; } proxy_set_header Authorization "Basic XXXXXXXXXXX"; #prerender server needs authentication proxy_set_header X-Real-IP $remote_addr; proxy_set_header HOST $http_host; proxy_set_header X-NginX-Proxy true; proxy_redirect off; if ($prerender = 1) { rewrite .* /$scheme://$host$request_uri? break; proxy_pass http://localhost:3456; break; } #otherwise should use the fastcgi proxy fastcgi_intercept_errors on; fastcgi_pass 127.0.0.1:9000; fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
请注意,在我的开发环境中,我也有一个位置块来启用phpmyadmin。 以前的configuration不能按预期工作,因为它始终使用fastcgi_pass。
有什么build议?
提前致谢。