admin管理员组文章数量:1406040
I'm pretty new to nginx and would love some insight on how to get this to work. Basically I have a proxy set up for my angular app that I want users to use. If it is a google bot, I want to check if I have a prerendered html (for seo) and if I do return that instead. However, nginx is testing my patience lol. How can I get my config to serve the html? Right now I can return the path to the file and the file is there but can't get seem to serve it.
I've tried using try_files $static_file @proxy but that just gave me 404s and 403s. I know there has to be some way to make this work. Please HELP!
sites-enabled for reference
location / {
set $isBot 0;
if ($http_user_agent ~* "googlebot| a bunch more but I removed them for now">
set $isBot 1;
}
set $static_file /var/www/main/static$uri/index.html;
set $render 0;
if (-f $static_file) {
set $render 1$isBot;
}
if ($render = 11) {
# TODO HELP just serve this html I cant get it to work
rewrite ^ $static_file;
}
# proxy to my server running spa
proxy_pass http://localhost:4200;
proxy_http_version 1.1;
proxy_buffering off;
proxy_connect_timeout 60s;
proxy_read_timeout 5400s;
proxy_send_timeout 5400s;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_cache_bypass $http_upgrade;
}
本文标签: nginxPrerendering html if they exist for bots but users use proxyStack Overflow
版权声明:本文标题:nginx - Prerendering html if they exist for bots but users use proxy - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744964411a2634854.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论