且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Capistrano + nginx在单个数字海洋飞沫中部署多个Rails应用程序

更新时间:2023-11-01 11:46:16

对于每个应用,您需要确保所使用的服务器正在不同的套接字上监听。



您必须在Nginx配置中添加另一个服务器块,例如低,

 上游app_one {
#server1 SOCK文件的路径
}

上游app_two {
#server2的SOCK文件
的路径}

服务器{
监听80;
server_name IP;

#先前定义的应用程序根目录
root / root / app_one / public;

try_files $ uri / index.html $ uri @app;

位置@app {
proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
proxy_set_header主机$ http_host;
proxy_redirect关闭;
proxy_pass http:// app_one;
}

error_page 500502503504 / 500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}

服务器{
听8080;
server_name IP;

#先前定义的应用程序根目录
root / root / app_two / public;

try_files $ uri / index.html $ uri @app;

位置@app {
proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
proxy_set_header主机$ http_host;
proxy_redirect关闭;
proxy_pass http:// app_two;
}

error_page 500502503504 / 500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}


I have a rails application running on a digital ocean server with IP xxx.xxx.xxx.xx .the deployed with Capistrano was easy now running with ease.Now I'm thinking to deploy another application to the same server using capistrano, After many research i'm not getting any proper solutions for my doubts or cant find any best tutorials for this.

What are the essential steps to look after before deploying the second application to the server?

Which nginx port the second application should listen to, 80 is default and the first application is already listening to that.?

How to access the second application after if deployed to the same droplet, now i can access the first application using the ip.?

For each app, you need to make sure whatever server you are using is listening on a different socket.

After that, you have to add another server block in Nginx configurations like below,

upstream app_one {
    # Path to server1 SOCK file
}

upstream app_two {
    # Path to server2 SOCK file
}

server {
    listen 80;
    server_name IP;

    # Application root, as defined previously
    root /root/app_one/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;
        proxy_pass http://app_one;
    }

    error_page 500 502 503 504 /500.html;
    client_max_body_size 4G;
    keepalive_timeout 10;
} 

server {
    listen 8080;
    server_name IP;

    # Application root, as defined previously
    root /root/app_two/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;
        proxy_pass http://app_two;
    }

    error_page 500 502 503 504 /500.html;
    client_max_body_size 4G;
    keepalive_timeout 10;
}