如何在任何Web服务器Apache或Mongrel或其他任何东西中运行简单的ruby脚本

如何解决如何在任何Web服务器Apache或Mongrel或其他任何东西中运行简单的ruby脚本

|| 对我来说似乎很有趣,当我搜索与红宝石有关的东西时,所有与红宝石相关的结果都会弹出。因此,没有人再使用原始红宝石了吗? 但是,我是红宝石的新手。今天早上,我只想在Web服务器上运行一个简单的hello world ruby​​脚本,首先是Apache 2,然后尝试了杂种。但不幸的是我失败了。我已尽一切可能在Google上进行了搜索,但结果仅显示了关于红宝石的信息。那么,是否真的有任何方法可以在任何Web服务器上运行ruby脚本,或者即使我只想做一个hello world应用程序,也必须使用ror?     

解决方法

        Sinatra可能是从没有Rails的Web服务器上运行Ruby脚本的最佳选择。 在这里看看:http://www.sinatrarb.com 从Sinatra文档:
require \'sinatra\'

get \'/hi\' do
  \"Hello World!\"
end
然后,运行:
$ gem install sinatra
$ ruby -rubygems hi.rb
== Sinatra has taken the stage ...
>> Listening on 0.0.0.0:4567
只需在浏览器中转到http://0.0.0.0:4567,您就应该找到\“ Hello World \” ... 除此之外,由于您还会询问有关在Apache或其他Web服务器上运行的信息,因此您可能需要查看有关将新的基于Sinatra的应用程序部署到Apache或Nginx的教程: Apache:http://www.pastbedti.me/2009/11/deploying-a-sinatra-app-with-apache-and-phusion-passenger-aka-mod_rack/和http://www.giantflyingsaucer.com/blog /?p = 1716 Nginx:http://tommy.chheng.com/2009/06/09/deploying-a-sinatra-app-on-nginx-passenger-with-capistrano-and-git/ 请注意,这两个教程都涵盖了通过Passenger运行Sinatra(http://www.modrails.com/-不要被\“ modrails \”名称所困扰)),我在部署应用程序时很幸运在Apache和Nginx下。     ,        您可以将Apache配置为例如将.rb文件作为CGI脚本运行,然后在脚本顶部添加一个shebang行(
#!/path/to/your/ruby
或maybe3ѭ)。不过,这并不是最佳选择,因为它会为每个请求启动一个新的解释器。     ,        运营红宝石网站最常用的方式是乘客:http://www.modrails.com/ 安装起来并不难,您可以使用,这是他的Apache文档:http://www.modrails.com/documentation/Users%20guide%20Apache.html#_deploying_a_ruby_on_rails_application 您的应用程序必须是有效的机架应用程序,这是最小的问候世界(假设/ app是您应用程序的根文件夹): /app/config.ru
require \'rack\'
require \'app\'
run(app)
/app/app.rb
app = proc do |env|
  [
    # http status code
    200,# headers
    {\'Content-Type\' => \'text/html\'},# html body
    [\"<head><title>Test Page</title></head><body>Hello World !</body>\"]
  ]
end
保存上面的文件,然后创建子文件夹/ app / public(乘客需要此子文件夹才能检测到ruby / rails / sinatra应用程序),并在您的apache配置中将/ app / public用作DocumentRoot。 这可能看起来很可怕,但这是用于生产部署的,在开发中,您真的不想弄乱真实的服务器。 运行上面提供的config.ru文件,您需要做的就是:
$ gem install rack
$ rackup config.ru
或者,如果您想更接近生产系统:
$ gem install passenger
$ cd /app
$ passenger start
这将为您安装带旅客的nginx服务器并运行您的应用程序。 在大多数情况下,您永远不会直接使用机架,而是在轨道,sinatra或其他框架上使用ruby为您生成html(它们现在都在下面的机架中提供与Web服务器一起使用的通用api)。     ,        Ruby 1.9.2+简单命令。
ruby -run -e httpd . -p 5000
来自本文http://til.justincampbell.me/start-an-http-server-with-ruby-run/ 其他文章https://gist.github.com/willurd/5720255     ,        我听说mod_ruby很好。与
#!/path/to/your/ruby
不同,mod_ruby不会产生新的ruby解释器。 https://github.com/shugo/mod_ruby     ,        从您的应用程序根目录运行。
ruby -r webrick -e \"s = WEBrick::HTTPServer.new(:Port => 8000,:DocumentRoot => Dir.pwd); trap(\'INT\') { s.shutdown }; s.start\"
    ,        
#!/usr/bin/env ruby  //shebang line to indicate path to ruby.
require \'cgi\'       //cgi file to create a simple cgi object.
cgi = CGI.new      //instantiating a cgi object. 
puts cgi.header   //thats telling the server about the type(html).
puts \"hello\"      // thats the output on the browser.
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-