ror的生产环境的搭建过程当中可以有多种web server和app server的选择和搭配,其中nginx + mongrel的组合是众多选择当中性能突出的一种,因此,手动搭建一个nginx + mongrel的ROR环境让自己的rails程序流畅的运行便成了事在必行的工作。
建议在搭建ROR的生产过程之前,能够对javaeye老大robbin的关于ROR服务器的相关文章进行阅读,以加深自己对ROR运行环境的认识,这样在大家搭建任何一种主流ROR生产环境的时候,都能明白为什么会这样选择和搭配,充分了解其内部原理,更能够把技术运用自如。
本篇文章主要是介绍在linux环境下搭建nginx + mongrel的集群环境,nginx作为反向代理服务器,里面有很多详细的参数配置没有涉及到,对web server的性能调优望大家用google自行解决一些实际遇到的性能瓶颈问题
我使用的linux环境是redhat5,下载的ruby版本为1.8.7
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream mongrel{
server 192.168.1.100:3000;
}
server {
listen 80;
server_name localhost;
index index.html index.htm;
charset utf-8;
#access_log logs/host.access.log main;
location / {
root /data/myProject/public;
index index.html index.htm;
proxy_pass http://mongrel;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov)${
# root /data/rails_code/test/public;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}