对于某些angularJS URL,Nginx有时会返回404错误

我正在使用Nginx服务器浏览基于AngularJS的网站(HTML模式为True,以避免#在URL中)。 除此之外,我configuration了Varnish以减less服务器上的负载。 所以Varnish运行在80端口,Nginx运行在81端口。我使用prerender.io来进行AngularJS网站的search引擎优化。

问题是,prerender尝试重新cachingangular度URL时,Nginx会返回404错误代码。

我的nginx.conf如下:

server { listen 81 default_server; listen [::]:81 default_server; server_name abcxyzabc.com; root /var/www/html/abcxyzabc/; location / { proxy_set_header X-Prerender-Token ****************; set $prerender 0; if ($http_user_agent ~* "baiduspider|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; } #resolve using Google's DNS server to force DNS resolution and prevent caching of IPs resolver 8.8.8.8; if ($prerender = 1) { #setting prerender as a variable forces DNS resolution since nginx caches IPs and doesnt play well with load balancing set $prerender "service.prerender.io"; rewrite .* /$scheme://$host$request_uri? break; proxy_pass http://$prerender; } location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 30d; } location /status { # Turn on nginx stats stub_status on; # I do not need logs for stats access_log off; # Security: Only allow access from localhost IP # allow 127.0.0.1; # Send rest of the world to /dev/null # deny all; } gzip on; gzip_disable "msie6"; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_buffers 16 8k; gzip_http_version 1.1; gzip_min_length 256; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon; error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } location ~ /\. { deny all; } } server { listen 81; server_name www.xyzabcxyz.com; return 301 $scheme://xyzabcxyz.com$request_uri; proxy_set_header X-Prerender-Token ***************; } 

通过上面的nginxconfiguration文件,当prerender尝试重新caching这些URL时,Nginx会返回404错误页面。 一段时间后,相同的url工作正常。 在nginxconfiguration中插入prerender代码之后引入了这种情况。 一切都很好之前。 请帮我一下 任何解决scheme/build议将有所帮助。