Created
June 5, 2020 07:43
-
-
Save yatishbalaji/ca1527d81ce5b8e52154a8540ef60930 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # cache directive for all static apps | |
| index index.html; | |
| ssl_certificate /etc/nginx/ssl/ssl-bundle.crt; | |
| ssl_certificate_key /etc/nginx/ssl/star.quezx.com.key; | |
| # maintenance mode if file maintenance_on.html present | |
| if (-f $document_root/maintenance_on.html) { | |
| return 503; | |
| } | |
| error_page 503 @maintenance; | |
| location @maintenance { | |
| rewrite ^(.*)$ /maintenance_on.html break; | |
| } | |
| # cache.appcache, your document html and data | |
| location ~* \.(?:manifest|appcache|html?|xml|json)$ { | |
| expires -1; | |
| } | |
| # Media: images, icons, video, audio, HTC | |
| location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|eot|otf|woff|woff2|ttf|svg|svgz|mp4|ogg|ogv|webm|htc)$ { | |
| expires 1M; | |
| access_log off; | |
| add_header Cache-Control "public"; | |
| } | |
| # CSS and Javascript | |
| location ~* \.(?:css|js)$ { | |
| expires 1y; | |
| access_log off; | |
| add_header Cache-Control "public"; | |
| } | |
| location / { | |
| #if ($args !~* _v=110917) { | |
| # return 301 https://$server_name$uri?_v=110917&$args; | |
| #} | |
| #try_files $uri $uri/ /index.html; | |
| try_files $uri $uri/ @prerender; | |
| expires -1; | |
| } | |
| location @prerender { | |
| #proxy_set_header X-Prerender-Token YOUR_TOKEN; | |
| set $prerender 0; | |
| if ($http_user_agent ~* "googlebot|bingbot|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; | |
| } | |
| #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 "localhost:3200"; | |
| rewrite .* /$scheme://$host$request_uri? break; | |
| proxy_pass http://127.0.0.1:3000; | |
| } | |
| if ($prerender = 0) { | |
| rewrite .* /index.html break; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment