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
class Account < ActiveRecord::Base | |
def withdraw(amount) | |
# ... | |
end | |
def deposit(amount) | |
# ... | |
end | |
def close! |
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
class Account < ActiveRecord::Base | |
def withdraw(amount) | |
# ... | |
end | |
def deposit(amount) | |
# ... | |
end | |
def close! |
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
require "benchmark" | |
user = User.find_by_name("Teemo") | |
# See the time it takes to count the comments of a post in an n+1 query | |
puts Benchmark.realtime { user.posts.each { |post| puts post.comments.count } } | |
# See the time it takes to count the comments of a post with eager-loading | |
# Should be faster | |
puts Benchmark.realtime { user.includes(:posts).posts.each { |post| puts post.comments.count } } |
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
http { | |
# The `limit_req_zone` directive here prevents a single ip | |
# address from making more than 30 requests per minute. | |
# The `$binary_remote_addr` tells nginx to use the remote address | |
# as the "key" for rate limiting. The zone is used to define a | |
# name and size where excessive requests are stored. | |
limit_req_zone $binary_remote_addr zone=my_zone:12m rate=30r/m; | |
location /do_not_dos_plz { |
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 { | |
# Deny all ip addresses from range 192.168.1.0 - 192.168.1.255 | |
# since the /24 means the first 24 bits of the ip address (ie. 192.168.1) | |
# is the network number, so deny all ips that belong to that network number. | |
deny 192.168.1.0/24; | |
allow all; | |
location /admin { |
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
# If there the upstream server errors, we want to with an error page. | |
# Note the `location` directive here is performing a regex match. | |
location ~* (script1|script2|script3)\.php$ { | |
proxy_pass http://192.168.0.1; | |
# The `error_page` directive will return the document file | |
# 50x.html depending on the upstream error. | |
error_page 500 502 503 504 /50x.html; | |
} |
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
location @proxy { | |
# if an upstream server supports SSL, simply change the protocol | |
# to https. | |
proxy_pass https://192.168.0.1; | |
# If the authenticity of the upstream server needs to be verified | |
# then enable it using the `proxy_ssl_verify` directive. This will | |
# check the upstream server's certificate against certificate authorities | |
# which are stored in /etc/ssl/certs | |
proxy_ssl_verify on; |
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
http { | |
server { | |
upstream upstream_server { | |
server unix:/tmp/rails.sock; | |
} | |
# This defines a "named location" called @proxy, which can be | |
# referenced elsewhere in this configuration. It's sort of like | |
# a variable for locations. |
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
http { | |
server { | |
listen 80; | |
server_name myreverseproxy.com; | |
# The `upstream` directive defines an upstream server that can be referenced | |
# in the rest of this file. In this case, it's a web application (ie. Rails/Rack) | |
# that is listening at the given unix socket. | |
upstream upstream_server_name { | |
server unix:/tmp/rack.sock; |
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
# Every `http` block must contain at least one `server` block which | |
# defines http and/or https virtual hosts. | |
server { | |
# Have a server listen to port 80, the standard HTTP port | |
listen 80; | |
# `server_name` creates a virtual host and sets its names | |
server_name staticcontent.com; | |