Last active
May 19, 2020 04:26
-
-
Save absk1317/69da58b25e3308abb2d2fd7cd7376065 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
server { | |
server_name xyz.com; | |
root /home/ubuntu/www; | |
large_client_header_buffers 4 16k; | |
client_max_body_size 4G; | |
keepalive_timeout 10; | |
gzip_static on; | |
location / { | |
error_page 404 =200 /index.html; | |
set $prerender 0; | |
if ($http_user_agent ~* "googlebot|SerendeputyBot|baiduspider|twitterbot|telegrambot|whatsapp|facebookexternalhit|rogerbot|linkedinbot|embedly|showyoubot|outbrain|pinterest|slackbot|W3C_Validator|curl") { | |
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)") { | |
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) { | |
# prerender is running locally in port 3000 | |
proxy_pass http://127.0.0.1:3000/$scheme://$host${uri}; | |
} | |
} | |
if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){ | |
return 405; | |
} | |
listen 443 ssl http2; # managed by Certbot | |
ssl_certificate /path/to/cert'; | |
ssl_certificate_key /path/to/key'; | |
} | |
server { | |
if ($host = xyz.com) { | |
return 301 https://$host$request_uri; | |
} | |
server_name xyz.com; | |
listen 80; | |
return 404; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment