Example Nginx Configuration File Simple Installation
A template for your simple installation nginx configuration file. Edit to suit.
Filename: nginx-conf-example.txt ( download )
Size: 7 KB
Document type: text/plain ( Replace description with document text )
- Walter McGinnis, 2007-08-13
- updated based on http://brainspl.at/nginx.conf.txt
- see there for comments on each option
user your_user_account your_user_account_or_group_if_different;
worker_processes 6;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include conf/mime.types;
default_type application/octet-stream;
- configure log format
log_format main ‘$remote_addr – $remote_user [$time_local] ’
’"$request" $status $body_bytes_sent “$http_referer” ’
’"$http_user_agent" “$http_x_forwarded_for”’;
- main error log
error_log logs/nginx_error.log debug;
- rewrite_log on; # I have yet to find where this gets saved to :(
- output compression saves bandwidth
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
- your_app
-—————————————————————————-
- redirect “www.your_app.com” to “your_app.com”
- you may want to do the reverse
server {
listen 80;
server_name www.your_app.com;
location / {
rewrite ^(.*)$ http://your_app.com$1 last;
}
}
- add listeners on ports here as needed for your mongrel cluster
- i.e. server 127.0.0.1:8001;
- server 127.0.0.1:8002;
- etc
upstream your_app {
server 127.0.0.1:8000;
}
- for non-ssl traffic, i.e. http
server {
listen 80;
server_name your_app.com;
- Set the max size for file uploads
- we set this high here and manage it
- within our app’s system setting for max file size
client_max_body_size 500M;
- doc root
root /your_home_directory_path/apps/your_app/public;
- this rewrites all the requests to the maintenance.html
- page if it exists in the doc root. This is for capistrano’s
- disable web task
if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html last;
break;
}
- needed to forward user’s IP address to rails
proxy_set_header X-Real-IP $remote_addr;
- needed for HTTPS
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect false;
proxy_max_temp_file_size 0;
- If the file exists as a static file serve it directly without
- running all the other rewite tests on it
if (-f $request_filename) {
break;
}
- check for index.html for directory index
- if its there on the filesystem then rewite
- the url to add /index.html to the end of it
- and then break to send it to the next config rules.
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
- this is the meat of the rails page caching config
- it adds .html to the end of the url and then checks
- the filesystem for that file. If it exists, then we
- rewite the url to have explicit .html on the end
- and then send it on its way to the next config rule.
- if there is no file on the fs then it sets all the
- necessary headers and proxies to our upstream mongrels
if (-f $request_filename.html) {
rewrite (.*) $1.html break;
}
- for ssl encrypted traffic, i.e. https
server {
listen 443;
server_name your_app.com;
- Set the max size for file uploads
- we set this high here and manage it
- within our app’s system setting for max file size
client_max_body_size 500M;
- doc root
root /your_home_directory_path/apps/your_app/public;
- this rewrites all the requests to the maintenance.html
- page if it exists in the doc root. This is for capistrano’s
- disable web task
if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html last;
break;
}
- needed to forward user’s IP address to rails
proxy_set_header X-Real-IP $remote_addr;
- needed for HTTPS
proxy_set_header X_FORWARDED_PROTO https;
- If the file exists as a static file serve it directly without
- running all the other rewite tests on it
if (-f $request_filename) {
break;
}
- check for index.html for directory index
- if its there on the filesystem then rewite
- the url to add /index.html to the end of it
- and then break to send it to the next config rules.
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
- this is the meat of the rails page caching config
- it adds .html to the end of the url and then checks
- the filesystem for that file. If it exists, then we
- rewite the url to have explicit .html on the end
- and then send it on its way to the next config rule.
- if there is no file on the fs then it sets all the
- necessary headers and proxies to our upstream mongrels
if (-f $request_filename.html) {
rewrite (.*) $1.html break;
}
}
was the last to edit Example Nginx Configuration File Simple Installation
on Jul 14th, 2009 at 9:59 PM
created Example Nginx Configuration File Simple Installation
on Jan 7th, 2008 at 2:12 AM