在 Ruby on Rails 中部署环境特定的 .htaccess 文件

发布于 2024-12-01 08:07:59 字数 254 浏览 0 评论 0原文

我有一个 .htaccess 文件,其中一行指定了我正在运行的应用程序的环境(暂存、生产等)。

RackEnv staging

使用 capistrano 和 capistrano-ext 处理环境特定部署的最佳方法是什么?

以某种方式在 capistrano 任务中动态写入它? 符号链接到特定于每个部署的现有共享 .htaccess,与数据库.yml 的方式非常相似?

还有其他选择吗?谢谢

I have a .htaccess file with a line that specifies the environment for the application I am running (staging, production etc..)

RackEnv staging

Whats the best way to handle this for environment specific deployments with capistrano and capistrano-ext?

somehow write to it dynamically in a capistrano task?
symbolically link to an existing, shared .htaccess that is specific for each deployment, much in the same way as you do for database.yml?

are there any other options? thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

您可以将其添加到该应用程序的 apache 配置文件中,而不是将其放入您的 .htaccess 文件中,通常是 /etc/apache2/sites-available/yoursite

下面是一个与您的设置类似的文件示例。 ..

<VirtualHost *:80>
    ServerName  yoursite.com
            ServerAlias yoursite.* 

    DocumentRoot /var/www/httpdocs/current/public

    <Directory /var/www/httpdocs/current/>
        Allow from all
        Options -MultiViews
    </Directory>

    RackEnv staging
    RailsEnv staging

    # Logfiles
    ErrorLog  /var/www/logs/error.log
    CustomLog /var/www/logs/access.log combined
</VirtualHost>

然后在您的deploy.rb文件中分离出站点特定的内容,就像这样...

task :staging do
    set :application, "yoursite"
    set :repository, "yoursite.git"
    set :branch, "master"
    set :deploy_to, "/var/www/httpdocs/currebt"
    server "staging.yoursite.com", :app, :web, :db, :primary => true
    set :rails_env, "staging"
end

如果所有这些都已设置好,那么您可以运行

cap staging deploy

Rather than put this in your .htaccess file you could add it to your apache config file for that app, typically this would be /etc/apache2/sites-available/yoursite

Here is an example of a file such as this with your setup ...

<VirtualHost *:80>
    ServerName  yoursite.com
            ServerAlias yoursite.* 

    DocumentRoot /var/www/httpdocs/current/public

    <Directory /var/www/httpdocs/current/>
        Allow from all
        Options -MultiViews
    </Directory>

    RackEnv staging
    RailsEnv staging

    # Logfiles
    ErrorLog  /var/www/logs/error.log
    CustomLog /var/www/logs/access.log combined
</VirtualHost>

Then in your deploy.rb file separate out the site specific stuff, like this ...

task :staging do
    set :application, "yoursite"
    set :repository, "yoursite.git"
    set :branch, "master"
    set :deploy_to, "/var/www/httpdocs/currebt"
    server "staging.yoursite.com", :app, :web, :db, :primary => true
    set :rails_env, "staging"
end

If all that is setup you can then run

cap staging deploy
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文