【问题标题】:How can I gracefully restart thin + nginx?我怎样才能优雅地重启瘦+ nginx?
【发布时间】:2012-07-24 08:34:47
【问题描述】:

我的瘦服务器配置了 nginx,我的 ROR 应用程序正在其上运行。

在我发布代码更新时运行 thin restart 会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重新启动正在运行的瘦实例,但我找不到一个好的解决方案。

有没有人能够做到这一点?

【问题讨论】:

  • “优雅地”是什么意思?如果需要重启,需要重启。
  • "gracefully" 意味着它不会丢弃当前连接,直到它们被处理。
  • 这就是 Unicorn 的做法: 1- 分叉主进程和工作进程。 2-将所有新请求发送给新主人。 3-向所有旧进程发送终止信号以在完成后终止。这是优雅的。

标签: ruby-on-rails ruby nginx capistrano thin


【解决方案1】:
# Restart just the thin server described by that config
sudo thin -C /etc/thin/mysite.yml restart 

Nginx 将继续运行和代理请求。如果您将 Nginx 设置为使用多个上游服务器,例如

server {
  listen        80;
  server_name  myapp.mysite.com;
  # ...
  location / {
    try_files $uri $uri/index.html /cache$uri.html $uri.html @proxy;
  }
  location @proxy {
    proxy_pass http://myapp.rails;
  }
}

upstream myapp.rails {
   server 127.0.0.1:9001 max_fails=1 fail_timeout=10s;
   server 127.0.0.1:9002 max_fails=1 fail_timeout=10s;
   server 127.0.0.1:9003 max_fails=1 fail_timeout=10s;
}

...然后每个实例将依次重新启动,如果其中一个代理关闭,Nginx 将自动路由请求。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-16
    • 2021-10-06
    • 1970-01-01
    • 2020-04-06
    • 1970-01-01
    相关资源
    最近更新 更多