server {
listen 80;
server_name www.edijin.net;
access_log /data/wwwlogs/youdomain.com_nginx.log combined;
index index.html index.htm index.php index.jsp;
root /usr/local/apache-tomcat-7.0.82/webapps/ROOT;
location / {
try_files $uri @prerender;
}
location @prerender {
proxy_set_header X-Prerender-Token BR9ODfIWe0KBuInh0jir;
set $prerender 0;
if ($http_user_agent ~* "baiduspider|Sogou web spider|360spider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator") {
set $prerender 1;
}
if ($args ~ "_escaped_fragment_") {
set $prerender 1;
}
if ($http_user_agent ~ "Prerender") {
set $prerender 0;
}
if ($uri ~* "\.(js|css|xml|less|png|jpg|jpeg|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpg|mpeg|tif|wav|mov|psd|ai|xls|mp4|m4a|swf|dat|dmg|iso|flv|m4v|torrent|ttf|woff|svg|eot)") {
set $prerender 0;
}
-sharpresolve using Google"s DNS server to force DNS resolution and prevent caching of IPs
-sharpresolver 8.8.8.8;
if ($prerender = 1) {
-sharpsetting prerender as a variable forces DNS resolution since nginx caches IPs and doesnt play well with load balancing
-sharpset $prerender "service.prerender.io";
set $prerender "127.0.0.1:3000";
rewrite ^(.+)$ /$scheme://$host$request_uri? break;
-sharprewrite .* /$scheme://$host$request_uri? break;
proxy_pass http://$prerender;
}
if ($prerender = 0) {
rewrite ^(.+)$ /index.html break;
}
}
}
this is my nginx configuration file. Currently, pre-rendering is started only for crawlers and specific url, that is, $prerender = 1.
I want the pre-rendering service to always run to achieve the same effect as nuxt. I really have a headache in the front-end nginx configuration and don"t know how to change it.