← All posts

实现网打算换成puma来跑

将unicorn换成puma的原因:

  • 节省内存 ,提高效率
  • Capistrano部署集成(capistrano3-puma)

以下为手动配置方法: 启动puma

text
1bundle exec puma -b unix:///tmp/puma.sock -e production --daemon

nginx配置例子: ​

text
1upstream shixian {
2 server unix:///tmp/puma.sock;
3}
4
5server {
6 listen 80;
7 server_name dev.shixian.com;
8
9 # ~2 seconds is often enough for most folks to parse HTML/CSS and
10 # retrieve needed images/icons/frames, connections are cheap in
11 # nginx so increasing this is generally safe...
12 keepalive_timeout 5;
13
14 # path for static files
15 root /home/deploy/apps/shixian/public;
16 access_log /home/deploy/apps/shixian/log/nginx.access.log;
17 error_log /home/deploy/apps/shixian/log/nginx.error.log info;
18
19 # this rewrites all the requests to the maintenance.html
20 # page if it exists in the doc root. This is for capistrano's
21 # disable web task
22 if (-f $document_root/maintenance.html) {
23 rewrite ^(.*)$ /maintenance.html last;
24 break;
25 }
26
27 location / {
28 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
29 proxy_set_header Host $http_host;
30
31 # If the file exists as a static file serve it directly without
32 # running all the other rewite tests on it
33 if (-f $request_filename) {
34 break;
35 }
36
37 # check for index.html for directory index
38 # if its there on the filesystem then rewite
39 # the url to add /index.html to the end of it
40 # and then break to send it to the next config rules.
41 if (-f $request_filename/index.html) {
42 rewrite (.*) $1/index.html break;
43 }
44
45 # this is the meat of the rack page caching config
46 # it adds .html to the end of the url and then checks
47 # the filesystem for that file. If it exists, then we
48 # rewite the url to have explicit .html on the end
49 # and then send it on its way to the next config rule.
50 # if there is no file on the fs then it sets all the
51 # necessary headers and proxies to our upstream pumas
52 if (-f $request_filename.html) {
53 rewrite (.*) $1.html break;
54 }
55
56 if (!-f $request_filename) {
57 proxy_pass http://shixian;
58 break;
59 }
60 }
61
62 # Now this supposedly should work as it gets the filenames with querystrings that Rails provides.
63 # BUT there's a chance it could break the ajax calls.
64 location ~* \.(ico|css|gif|jpe?g|png|js)(\?[0-9]+)?$ {
65 expires max;
66 break;
67 }
68
69 # Error pages
70 # error_page 500 502 503 504 /500.html;
71 location = /500.html {
72 root /home/deploy/apps/shixian/public;
73 }
74}