Nginx+Unicorn+rails多项目
编程技术  /  houtizong 发布于 3年前   63
tar zxvf nginx-0.7.67.tar.gz cd nginx-0.7.67/ ./configure make make install
cd /usr/local/nginx/sbin ./nginx
upstream config_manager { server unix:/tmp/nginx/sockets/config_manager_unicorn.sock fail_timeout=0; }
server { listen 80; server_name ***.******.com; ……… …… location ~ ^/config { (注:这是一个正则表达式 匹配浏览器地址访地址 的path,这里以config开头的path在这里面处理,也可以直接写成 location /config) proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_pass http://config_manager;(注:这个config_manager 对应上面的upstream) }
gem install unicorn
# unicorn_rails -c /data/github/current/config/unicorn.rb -E production -Drails_env = ENV['RAILS_ENV'] || 'production'# 16 workers and 1 masterworker_processes (rails_env == 'production' ? 16 : 4)# Load rails+github.git into the master before forking workers# for super-fast worker spawn timespreload_app true# Restart any workers that haven't responded in 30 secondstimeout 30# Listen on a Unix data socket!!!!!!!!!!!!!!!!!!!!!!!=========下面这个地址要与nginx.conf的upstream相对应listen '/tmp/nginx/sockets/config_manager_unicorn.sock', :backlog => 2048### REE# http://www.rubyenterpriseedition.com/faq.html#adapt_apps_for_cowif GC.respond_to?(:copy_on_write_friendly=) GC.copy_on_write_friendly = trueendbefore_fork do |server, worker| ## # When sent a USR2, Unicorn will suffix its pidfile with .oldbin and # immediately start loading up a new version of itself (loaded with a new # version of our app). When this new Unicorn is completely loaded # it will begin spawning workers. The first worker spawned will check to # see if an .oldbin pidfile exists. If so, this means we've just booted up # a new Unicorn and need to tell the old one that it can now die. To do so # we send it a QUIT. # # Using this method we get 0 downtime deploys. old_pid = RAILS_ROOT + '/tmp/pids/unicorn.pid.oldbin' if File.exists?(old_pid) && server.pid != old_pid begin Process.kill("QUIT", File.read(old_pid).to_i) rescue Errno::ENOENT, Errno::ESRCH # someone else did our job for us end endendafter_fork do |server, worker| ## # Unicorn master loads the app then forks off workers - because of the way # Unix forking works, we need to make sure we aren't using any of the parent's # sockets, e.g. db connection!!!!!!!!!!!!!!!!!!!=====注释掉了第二行,主要是因为没有开启相应的memcache服务之类======!!!!!!!!!!!!!!! ActiveRecord::Base.establish_connection #CHIMNEY.client.connect_to_server # Redis and Memcached would go here but their connections are established # on demand, so the master never opens a socket ## # Unicorn master is started as root, which is fine, but let's # drop the workers to git:git begin uid, gid = Process.euid, Process.egid user, group = 'root', 'root' target_uid = Etc.getpwnam(user).uid target_gid = Etc.getgrnam(group).gid worker.tmp.chown(target_uid, target_gid) if uid != target_uid || gid != target_gid Process.initgroups(user, target_gid) Process::GID.change_privilege(target_gid) Process::UID.change_privilege(target_uid) end rescue => e if RAILS_ENV == 'development' STDERR.puts "couldn't change user, oh well" else raise e end endend
ENV['RAILS_RELATIVE_URL_ROOT'] = "/config"
worker_processes 3listen '/tmp/nginx/sockets/*****.sock', :backlog => 2048timeout 30preload_app truebefore_fork do |server, worker| old_pid = pid_file + '.oldbin' if File.exists?(old_pid) && server.pid != old_pid begin Process.kill("QUIT", File.read(old_pid).to_i) rescue Errno::ENOENT, Errno::ESRCH # someone else did our job for us end endend
# 只允许本机访问 server.bind = "localhost" # 从81端口启动 server.port = 81
http { # 新的项目 对应 new.domain.com 域名 server { listen 80; server_name new.domain.com; access_log logs/domain1.access.log main; index index.html; root /var/www/domain1.com/htdocs; } # 旧的项目 对应 old.domain.com 域名 server { listen 80; server_name old.domain.com; location / { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; # 转发给 81 端口的 lighttpd 处理 proxy_pass http://127.0.0.1:81; } } }
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接