现在 VPS 上用 Passenger + Nginx 跑了一个 App, 是参照论坛的 Wiki 配置的。 如果,我想要再部署一个 Rails App, 如何设置呢?
server {
listen 80;
server_name site-a.com;
root /var/www/site-a.com/current/public;
passenger_enabled on;
}
server {
listen 80;
server_name site-b.com;
root /var/www/site-b.com/current/public;
passenger_enabled on;
}
#3 楼 @springwq 这就要用 nginx 的 upstream 了。
upstream site-a {
server 127.0.0.1:5000; // 假设 site-a 开了一个进程监听 5000
}
upstream site-b {
server 127.0.0.1:6000; // 假设 site-b 开了一个进程监听 6000
}
server {
listen 80;
server_name site-a.com;
root /var/www/site-a.com/current/public;
try_files $uri/index.html $uri.html $uri @site-a;
location @site-a {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://site-a;
}
}
server {
listen 80;
server_name site-b.com;
root /var/www/site-b.com/current/public;
try_files $uri/index.html $uri.html $uri @site-b;
location @site-b {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://site-b;
}
}
thin 进程启动要另外管理。
使用 upstream
时,再 proxy_pass
时要加个 proxy_redirect off
,不然 Rails 的 root_url
就是 upstream 名而不是 http://site-a.com
了。
@Rei @luffycn 貌似 Thin 配置好复杂,对新手来说,我看了这篇 SO 文章,还是觉得 Passenger 比较适合新手。
http://stackoverflow.com/questions/4113299/ruby-on-rails-server-options