最近做微信相关开发, 需要部署一个服务器给微信应用做后台。
项目后端用 ruby on rails, 前端用 angularjs。服务器部署选择 nginx反向代理, rainbows起服务。(本来想用passenger的师兄不让。。。)
rainbows的配置文件放在rails的config目录下面, 修改GEM添加相应包就OK了。
rainbows 的配置文件:
# 注意这里设置要监听的sock文件路径, rainbows 就是利用这个文件和nginx通信的,
# 从而完成对nginx 反向代理过来的的请求相应的
# nginx 配置文件 upstream 也要做相应的配置:
# # Path to Unicorn SOCK file, as defined previousl # server unix:/下面listen设置的socket_path fail_timeout=1s; # } # 这种通信方式, 是linux 进程间通信的一种方式, 本地socket listen socket_path
# By default, the Unicorn logger will write to stderr. # Additionally, ome applications/frameworks log to stderr or stdout, # so prevent them from going to /dev/null when daemonized here: stderr_path err_path stdout_path out_path preload_app true before_fork do |server, worker| # # This allows a new master process to incrementally # # phase out the old master process with SIGTTOU to avoid a # # thundering herd (especially in the "preload_app false" case) # # when doing a transparent upgrade. The last worker spawned # # will then kill off the old master process with a SIGQUIT. old_pid = "#{server.config[:pid]}.oldbin" if old_pid != server.pid begin sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU Process.kill(sig, File.read(old_pid).to_i) rescue Errno::ENOENT, Errno::ESRCH end end # # Throttle the master from forking too quickly by sleeping. Due # to the implementation of standard Unix signal handlers, this # helps (but does not completely) prevent identical, repeated signals # from being lost when the receiving process is busy. # sleep 1 end after_fork do |server, worker| end
然后是nginx 的配置文件:#定义要反向代理到的服务器的位置
}
server { listen 80; server_name localhost; # 这里需要同步成对应rails应用的public目录 root /root/my_app/public;
try_files $uri/index.html $uri @app; location @app { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off;
#代理到前面up_stream 定义的位置 proxy_pass http://app; } error_page 500 502 503 504 /500.html; client_max_body_size 4G; keepalive_timeout 10; }
参考资料(抄袭原文):
https://www.digitalocean.com/community/tutorials/how-to-deploy-rails-apps-using-unicorn-and-nginx-on-centos-6-5
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:记rainbow + nginx 服务器部署, 微信后台搭建 - Python技术站