Created
November 28, 2010 18:30
-
-
Save bopm/719167 to your computer and use it in GitHub Desktop.
NGINX mongrel/unicorn configuration
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 { | |
server_name mydomain.com; | |
access_log /var/log/nginx/mydomain.access.log; | |
error_log /var/log/nginx/mydomain.error.log; | |
root /var/www/rails_app/public; | |
location ~ /\.svn/ { # мы очень не хотим, чтобы у нас одолжили код :) | |
deny all; | |
} | |
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ { # для графики ставим правильные заголовки. | |
expires max; | |
access_log off; | |
} | |
location / { | |
try_files /maintenance.html $uri @mongrel; # Пробуем отдавать: | |
# /maintenance.html в root, если его нет - | |
# физический файл в root, если его нет - | |
# отдаем запрос в локейшн @mongrel. | |
} | |
location @mongrel { | |
client_max_body_size 10m; # этот параметр дает возможность пользователям аплоадить большие файлы. Если не нужен - уберите. | |
client_body_buffer_size 128k; # откуда это появилось я уже не помню, будем считать меня адептом cargo культа. | |
proxy_set_header X-Real-IP $remote_addr; # Наше приложение нуждается в данных о ip адресе клиента. Хотя бы для того, чтобы логи были честными. | |
proxy_set_header X-Forwarded-for $remote_addr; # И о том, что за прокси тоже. | |
proxy_set_header Host $http_host; # Вот этот "проброс" позволяет нам поддерживать поддомены средствами нашего приложения. Иначе никак. | |
proxy_redirect off; # до тех пор, пока апстрим не публичен, мы должны все редиректы осуществлять на себя, а не на апстрим. | |
proxy_connect_timeout 90; # Как я и говорил, некоторые вещи самозародились. У меня работает, если у вас нет — wiki.nginx.org. | |
proxy_send_timeout 90; | |
proxy_read_timeout 90; | |
proxy_buffer_size 4k; | |
proxy_buffers 4 32k; | |
proxy_busy_buffers_size 64k; | |
proxy_temp_file_write_size 64k; | |
proxy_pass http://mongrel; # смотри в основной конфиг, там мы определили этот апстрим. | |
} | |
location /files { | |
internal; # Любой пытающийся запросить этот локейшн с улицы, получит 404. Мы же можем послать туда пользователя из любого контроллера, сказав | |
alias /var/files/; # response.headers['X-Accel-Redirect'] = File.join("/files", @file_name). | |
} | |
} |
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
user www; | |
worker_processes 5; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
use kqueue; | |
} | |
http { | |
include mime.types; | |
default_type application/octet-stream; | |
sendfile on; | |
gzip on; | |
gzip_http_version 1.0; | |
gzip_comp_level 2; | |
gzip_proxied any; | |
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; | |
gzip_disable msie6; | |
upstream mongrel { # ферма поднята на .2, nginx с .2 не участвует в пробросе. | |
server 192.168.1.2:3000; | |
server 192.168.1.2:3001; | |
server 192.168.1.2:3002; | |
server 192.168.1.2:3003; | |
server 192.168.1.2:3004; | |
} | |
include domains/mydomain.conf; | |
include domains/unicorn.conf; | |
} |
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
user www; | |
worker_processes 5; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
accept_mutex off; | |
} | |
http { | |
include mime.types; | |
default_type application/octet-stream; | |
sendfile on; | |
keepalive_timeout 65; | |
gzip on; | |
gzip_http_version 1.0; | |
gzip_proxied any; | |
gzip_min_length 500; | |
gzip_disable "MSIE [1-6]\."; | |
gzip_types text/plain text/html text/xml text/css | |
text/comma-separated-values | |
text/javascript application/x-javascript | |
application/atom+xml; | |
upstream unicorn { | |
server unix:/var/www/rails_app/tmp/sockets/unicorn.sock fail_timeout=0; | |
} | |
include domains/unicorn.conf; | |
} |
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 { | |
server_name unicorn.mydomain.com; | |
access_log /var/log/nginx/unicorn.mydomain.access.log; | |
error_log /var/log/nginx/unicorn.mydomain.error.log; | |
location / { | |
client_max_body_size 10m; | |
client_body_buffer_size 128k; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-for $remote_addr; | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
proxy_connect_timeout 90; | |
proxy_send_timeout 90; | |
proxy_read_timeout 90; | |
proxy_pass http://192.168.1.2; # Просто отправляем все запросы на все виды файлов на апстрим. | |
} | |
location /files { | |
internal; | |
alias /var/files/; | |
} | |
} |
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 { | |
server_name unicorn.mydomain.com; | |
access_log /var/log/nginx/mydomain.access.log; | |
error_log /var/log/nginx/mydomain.error.log; | |
root /var/www/rails_app/public; | |
location ~ /\.svn/ { | |
deny all; | |
} | |
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ { | |
expires max; | |
} | |
location / { | |
try_files /maintenance.html $uri @mongrel; | |
} | |
location @mongrel { | |
client_max_body_size 10m; | |
client_body_buffer_size 128k; | |
proxy_set_header X-Real-IP $http_x_real_ip; # Важное отличие от схемы с одним nginx'ом: на вложенных мы берем параметры из запроса, а не из окружения | |
proxy_set_header X-Forwarded-for $http_x_forwarded_for; # иначе получим в качестве ip адреса клиента 192.168.1.1. | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
proxy_connect_timeout 90; | |
proxy_send_timeout 90; | |
proxy_read_timeout 90; | |
proxy_buffer_size 4k; | |
proxy_buffers 4 32k; | |
proxy_busy_buffers_size 64k; | |
proxy_temp_file_write_size 64k; | |
proxy_pass http://unicorn; | |
proxy_ignore_headers X-Accel-Redirect; | |
proxy_pass_header X-Accel-Redirect; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment