Answer the question
In order to leave comments, you need to log in
How to use prerender for home page?
Site on Angular 1.6.0.
/**
* Режим html5 для адресной строки и роутера
*/
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
<meta name="fragment" content="!">
is present. https://domain.ru/about/?_escaped_fragment_=
, then everything is as it should be. https://domain.ru/?_escaped_fragment_=
, then an unrendered page is returned. upstream app {
# API запущен на 8080 порту
server 127.0.0.1:8080;
}
server {
listen 80;
server_name domain.ru www.domain.ru;
proxy_set_header Host domain.ru;
location / {
rewrite ^(.*)$ https://domain.ru$1 permanent;
}
return 301 https://domain.ru$request_uri;
}
server {
listen 443 ssl http2;
server_name domain.ru www.domain.ru;
root /var/www/domain.ru;
index index.html;
location / {
try_files $uri $uri/ @prerender;
}
location @prerender {
#proxy_set_header X-Prerender-Token YOUR_TOKEN;
set $prerender 0;
if ($http_user_agent ~* ".*(Yandex|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;
}
if ($prerender = 1) {
# prerender запущен на 8000 порту
set $prerender "127.0.0.1:8000";
rewrite .* /$scheme://$host$request_uri? break;
proxy_pass http://$prerender;
}
if ($prerender = 0) {
rewrite .* /index.html break;
}
}
location /api/ {
proxy_pass http://app;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question