Created
October 17, 2020 14:49
-
-
Save Biostate/6ee5606325f038c8bc3eeec2ca5441fd to your computer and use it in GitHub Desktop.
Prerender.io Nginx Configuration for Laravel
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
server { | |
listen YOUR_IP_ADDRESS; | |
server_name YOUR_URL; | |
error_log /var/log/httpd/domains/YOUR_URL.error.log error; | |
location / { | |
try_files $uri @prerender; | |
proxy_pass YOUR_IP_ADDRESS; | |
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|html|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls|xlsx|ppt|pptx|odf|odp|ods|odt|pdf|psd|ai|eot|eps|ps|zip|tar|tgz|gz|rar|bz2|7z|aac|m4a|mp3|mp4|ogg|wav|wma|3gp|avi|flv|m4v|mkv|mov|mpeg|mpg|wmv|exe|iso|dmg|swf)$ { | |
root /home/admin/web/YOUR_URL/public_html; | |
access_log /var/log/httpd/domains/YOUR_URL.log combined; | |
access_log /var/log/httpd/domains/YOUR_URL.bytes bytes; | |
expires max; | |
try_files $uri @fallback; | |
} | |
} | |
#Add your additional routes here | |
location ~ ^/(admin|api|oauth) { | |
proxy_pass YOUR_IP_ADDRESS; | |
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|html|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls|xlsx|ppt|pptx|odf|odp|ods|odt|pdf|psd|ai|eot|eps|ps|zip|tar|tgz|gz|rar|bz2|7z|aac|m4a|mp3|mp4|ogg|wav|wma|3gp|avi|flv|m4v|mkv|mov|mpeg|mpg|wmv|exe|iso|dmg|swf)$ { | |
root /home/admin/web/YOUR_URL/public_html; | |
access_log /var/log/httpd/domains/YOUR_URL.log combined; | |
access_log /var/log/httpd/domains/YOUR_URL.bytes bytes; | |
expires max; | |
try_files $uri @fallback; | |
} | |
} | |
location @prerender { | |
# proxy_set_header X-Prerender-Token TOKEN; | |
set $prerender 0; | |
if ($http_user_agent ~* "googlebot|bingbot|yandex|baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest\/0\.|pinterestbot|slackbot|vkShare|W3C_Validator|whatsapp") { | |
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; | |
} | |
if ($prerender = 0) { | |
rewrite .* /index.html break; | |
proxy_pass YOUR_IP_ADDRESS; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment