Last active
December 20, 2015 15:09
-
-
Save jeremyjbowers/6151934 to your computer and use it in GitHub Desktop.
Basic Nginx configuration for Inspections project.
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
# One process because we only have one core. | |
worker_processes 1; | |
# The Web server should run as a separate user | |
# because if it is compromised, it won't have | |
# permissions to do evil things. | |
user www-data; | |
# Where to keep the process id. | |
# /var/run is standard. | |
pid /var/run/nginx.pid; | |
# How to handle lots of events, e.g., requests. | |
# We use epoll and can handle up to 4096 | |
# concurrent connections. This is a lot. | |
events { | |
worker_connections 4096; | |
use epoll; | |
multi_accept on; | |
} | |
# Now, the block where we do server things. | |
http { | |
# Some basic nginx boilerplate. | |
# Know what legal mimetypes are. | |
include /etc/nginx/mime.types; | |
# Set a default mimetype. | |
default_type application/octet-stream; | |
# Set up an access and error log. | |
# Logging is good. | |
access_log /var/log/nginx/access.log; | |
error_log /var/log/nginx/error.log; | |
# Basic configuration you can cut-and-paste | |
# for your next project. | |
sendfile on; | |
keepalive_timeout 15; | |
tcp_nopush on; | |
tcp_nodelay on; | |
proxy_next_upstream error; | |
types_hash_max_size 2048; | |
server_names_hash_bucket_size 64; | |
# Okay, now a server block. This is | |
# where it starts to get good. | |
server { | |
# Listen on port 80. | |
listen 80; | |
# For requests to our domain name. | |
server_name inspections.jeremybowers.com; | |
# Don't send anything bigger than 50mb. | |
# This is not a problem. | |
client_max_body_size 50M; | |
# Set the filesystem root in case we need to | |
# serve a flat file. This will be important | |
# later. | |
root /var/www/inspections; | |
# A location block parses an URL path. | |
location ^~ /admin/ { | |
# If we're looking at /admin/, don't | |
# send the request to Varnish, or we | |
# will cache whichever logged in user | |
# first hit the page. This is bad (tm). | |
# Send this request straight to uWSGI. | |
uwsgi_pass 127.0.0.1:8002; | |
include /etc/nginx/uwsgi_params; | |
} | |
location / { | |
# Otherwise, send the requests through | |
# to Varnish on port 8000. | |
proxy_pass http://127.0.0.1:8000; | |
} | |
} | |
# NEXT. | |
# Now, listen on 8001, which is where Varnish | |
# will send requests which fail to find something | |
# in the cache. | |
server { | |
# Listen on 8001. | |
listen 8001; | |
# Listen for our domain. | |
server_name inspections.jeremybowers.com; | |
# Blah-blah-blah. | |
client_max_body_size 50M; | |
root /var/www/inspections; | |
# Okay, back to interesting. | |
location / { | |
# Send through to uWSGI, like we | |
# did for /admin/ URLs above. | |
# However, since we're a Varnish backend | |
# now, these responses can be cached. | |
# Caching is awesome. | |
uwsgi_pass 127.0.0.1:8002; | |
include /etc/nginx/uwsgi_params; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment