Skip to content

Instantly share code, notes, and snippets.

@salami-art
Created January 25, 2018 10:18
Show Gist options
  • Save salami-art/f7ea05ced0e1ca48689e231a41b79cb9 to your computer and use it in GitHub Desktop.
Save salami-art/f7ea05ced0e1ca48689e231a41b79cb9 to your computer and use it in GitHub Desktop.
upstream puma {
server unix:///home/ubuntu/apps/MyApp/shared/tmp/sockets/MyApp-puma.sock;
}
server {
listen 80 default_server deferred;
if ($http_user_agent ~* (banned|banned1|banned2)) {
return 403;
}
if ($http_user_agent == "-") {
return 403;
}
# server_name example.com;
root /home/ubuntu/apps/MyApp/current/public;
access_log /home/ubuntu/apps/MyApp/current/log/nginx.access.log;
error_log /home/ubuntu/apps/MyApp/current/log/nginx.error.log info;
location ^~ /public/ {
autoindex on;
alias /home/ubuntu/apps/MyApp/current/public/;
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @puma;
location @puma {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://puma;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 10M;
keepalive_timeout 10;
}
$ wget http://example.com/path -O /dev/null --user-agent="banned"
http://example.com/path
Connecting to example.com:80... connected.
HTTP request sent, awaiting response... 200 OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment