在 Apache 上运行 Ruby 应用程序

发布于 2024-09-06 02:43:43 字数 885 浏览 2 评论 0原文

我最近一直在学习 Ruby,我想将测试 Web 应用程序上传到我的服务器。但我不知道如何让它在我的共享主机上运行。

我的主机详细信息

  • 与 JustHost 共享主机(请参阅此处了解功能列表< /a>)
  • 操作系统:Linux
  • Apache:2.2.11
  • cPanel:11.25.0-STABLE
  • SSH 访问。
  • 可以安装 Ruby Gems。
  • 无法安装 Apache 模块。
  • 可以通过 cPanel“管理 Ruby on Rails 应用程序”。
  • 杂种宝石已安装。

我使用 Sinatra 构建了以下简单的 HelloWorld Ruby Rack 应用程序:

#!/usr/bin/ruby ruby
require 'rubygems'
require 'sinatra'
get '/hi' do
  "Hello World!"
end

我可以不知道如何“启动”应用程序。我是否需要告诉 Mongrel(或者 Apache)该应用程序以某种方式存在?我如何开始运行这个应用程序?如果需要,我很乐意提供更多信息。

I have been learning Ruby lately, and I want to upload a test web application to my server. But I can't figure out how to get it to run on my shared hosting.

My Hosting Details

  • Shared Hosting with JustHost (see here for list of features)
  • OS: Linux
  • Apache: 2.2.11
  • cPanel: 11.25.0-STABLE
  • No SSH access.
  • Can install Ruby Gems.
  • Can't install Apache modules.
  • Can "Manage Ruby on Rails Applications" through cPanel.
  • Mongrel gem is installed.

I built the following simple HelloWorld Ruby Rack app using Sinatra:

#!/usr/bin/ruby ruby
require 'rubygems'
require 'sinatra'
get '/hi' do
  "Hello World!"
end

I just can can't figure out how to "start" the application. Do I need to tell Mongrel (or maybe Apache) that the application exists somehow? How do I start this app running? I am happy to provide more info if needed.

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

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

发布评论

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

评论(1

久光 2024-09-13 02:43:43

首先,您必须在服务器启动时手动或通过脚本启动应用程序。只需执行 ruby​​ hi.rb 之类的操作(如 sinatra 网页上所述,它在端口 4567 上运行应用程序)。那么你有两个选择。 1) 您可以直接访问此应用程序: http://yourserver:4567/ 或 2) 您可以使用 apache作为代理。

如果你想使用 apache 作为代理,你必须使用虚拟主机服务器。例如:

NameVirtualHost hi.server:80
<VirtualHost hi.server:80>
    Servername hi.server
    RewriteEngine On
    <Proxy balancer://hi>
        BalancerMember http://127.0.0.1:4567
    </Proxy>
    ProxyPass / balancer://hi/
    ProxyPassReverse / balancer://hi/
</VirtualHost>

如果您有多个核心,您可以多次运行 hi.rb(每次在不同的端口上),并且只需添加新的 BalancerMember。您还可以使用指令打开 apache 缓存:CacheEnable mem /

firstly you have to start your application manualy or by script when the server is starting. Just do something like ruby hi.rb (as described on sinatra webpage it runs appication on the port 4567). Then you have two options. 1) You can access this application directly as: http://yourserver:4567/ or 2) you can use apache as a proxy.

If you want use apache as a proxy you have to use virtualhost servers. for example:

NameVirtualHost hi.server:80
<VirtualHost hi.server:80>
    Servername hi.server
    RewriteEngine On
    <Proxy balancer://hi>
        BalancerMember http://127.0.0.1:4567
    </Proxy>
    ProxyPass / balancer://hi/
    ProxyPassReverse / balancer://hi/
</VirtualHost>

And if you have ie multiple cores you can run hi.rb more then once (each time on diferent port) and you just add new BalancerMember. You can also switch on apache cache using directive: CacheEnable mem /

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