Skip to content

Instantly share code, notes, and snippets.

@slaveofcode
Last active October 19, 2016 04:08
Show Gist options
  • Save slaveofcode/2392473f8391b1307a334520f487df42 to your computer and use it in GitHub Desktop.
Save slaveofcode/2392473f8391b1307a334520f487df42 to your computer and use it in GitHub Desktop.
My simple nginx configuration used for aroound.com prerender
server{
listen 80;
server_name aroound.com;
return 301 http://www.aroound.com$request_uri;
}
server {
listen 80 default_server;
server_name www.aroound.com;
server_tokens off;
#charset koi8-r;
access_log /var/log/nginx/site.access.log main;
error_log /var/log/nginx/site.error.log;
gzip_static on;
gzip on;
set $root_path '/var/www/html/aroound';
root $root_path;
index index.php index.html index.htm;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ /index.html =404
# Redirect all links to index.html
#try_files $uri $uri/ /index.html @prerender;
try_files $uri @prerender;
}
location @prerender {
set $prerender 0;
if ($http_user_agent ~* "googlebot|yahoo|bingbot|baiduspider|yandex|yeti|yodaobot|gigabot|ia_archiver|facebookexternalhit|twitterbot|developers\.google\.com") {
set $prerender 1;
}
if ($args ~ "_escaped_fragment_|prerender=1") {
set $prerender 1;
}
if ($http_user_agent ~ "Prerender") {
set $prerender 0;
}
set $prerender_path "/prerender";
if ($prerender = 1) {
rewrite (.*) $prerender_path$request_uri? break;
proxy_pass http://api.aroound.com;
#proxy_pass http://service.prerender.io;
}
if ($prerender = 0) {
rewrite .* /index.html break;
}
}
location ~* .(gif|jpg|jpeg|png|ico|wmv|3gp|avi|mpg|mpeg|mp4|flv|mp3|mid|js|css|wml|swf)$ {
root /var/www/html/aroound;
}
}
upstream arooundapi {
server unix:///var/www/aroound/socket/aroound.sock;
}
server {
listen 80;
server_name api.aroound.com;
charset utf-8;
# Logging
error_log /var/log/nginx/aroound.error.log;
access_log /var/log/nginx/aroound.access.log;
#gzip_static on;
#gzip on;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /static {
alias /var/www/aroound/static; # your Django project's media files - amend as required
}
location /assets {
alias /var/www/aroound/assets; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass arooundapi;
include /var/www/aroound/uwsgi_params; # the uwsgi_params file you installed
# Add custom headers for options, head request
#if ($request_method ~ (OPTIONS|HEAD)) {
# add_header Access-Control-Allow-Origin *;
# add_header Access-Control-Allow-Methods "GET, POST, PUT, PATCH, OPTIONS";
# add_header Access-Control-Allow-Headers "Authorization, Content-Type, Accept";
# add_header Access-Control-Allow-Credentials true;
# add_header Content-Length 0;
# add_header Content-Type text/plain;
# add_header Access-Control-Max-Age 1728000;
#}
#if ($request_method = OPTIONS) {
# return 200;
#}
#add_header Access-Control-Allow-Origin *;
#add_header Access-Control-Allow-Credentials false;
#add_header Access-Control-Allow-Headers "Content-Type, Accept, Authorization, Origin, User-Agent";
#add_header Access-Control-Allow-Methods "GET, POST, PUT, PATCH, OPTIONS";
#proxy_set_header X-Forwarded-Protocol $scheme;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment