gpt4 book ai didi

ruby-on-rails - nginx 和 unicorn 上的多个 Rails 应用程序

转载 作者:太空宇宙 更新时间:2023-11-03 16:43:53 24 4
gpt4 key购买 nike

我使用 Screencast 335 部署到 VPS 教程成功设置了一个 Rails 站点。现在我想在新域上添加另一个 Rails 应用程序,但我对所需的步骤感到困惑。

在上面的设置中,sites-available 或/etc/nginx/nginx.conf 没有变化。唯一的配置在我的应用程序配置目录中的 unicorn.rb、unicorn_init.sh 和 nginx.conf 中。 nginx.conf 文件如下所示:-

upstream unicorn {
server unix:/tmp/unicorn.my_app.sock fail_timeout=0;
}
server {
listen 80 default deferred;
# server_name my_app.com.au www.my_app.com.au;
root /var/www/my_app/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}

在我的 Capistrano 食谱中我有这一行

sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"

添加第二个域仅仅是删除默认延迟监听和取消注释 server_name 部分然后为第二个应用程序使用不同的上游套接字名称和服务器名称重复此配置文件的问题吗?这行得通吗?我是否需要将此文件传输到可用站点并创建指向已启用站点的符号链接(symbolic link)?

最佳答案

在 unicorn.rb 中:

应用程序 1:

root = "/var/www/application_1/current"
working_directory root
pid "#{root}/tmp/pids/unicorn-app1.pid"
listen "/tmp/unicorn.app1.sock"

应用 2:

root = "/var/www/application_2/current"
working_directory root
pid "#{root}/tmp/pids/unicorn-app2.pid"
listen "/tmp/unicorn.app2.sock"

在 nginx.conf 中:

应用程序 1:

upstream app1_server {
server unix:/tmp/unicorn.app1.sock fail_timeout=0;
}

server {
listen 80;
server_name my_app_1.com www.my_app_1.com;
root /var/www/app1/current/public;

location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}

try_files $uri/index.html $uri @app1_server;
location @app1_server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app1_server;
}

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

应用 2:

upstream app2_server {
# point to app2 sock
server unix:/tmp/unicorn.app2.sock fail_timeout=0;
}

server {
listen 80;
server_name my_app_2.com www.my_app_2.com;
root /var/www/app2/current/public;

location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}

try_files $uri/index.html $uri @app2_server;
location @app2_server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app2_server;
}

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

关于ruby-on-rails - nginx 和 unicorn 上的多个 Rails 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14159689/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com