我尝试创建一个 test.rb 文件,将其放在公共目录中,然后像http://localhost:3000/test.rb一样调用它,但这似乎不起作用。它认为我正在尝试下载文件。我在这里想念什么?小脚本如下:
#!/usr/local/bin/ ruby
print "HTTP/1.0 200 OK\r\n"
print "Content-type: text/html\r\n\r\n"
print "<html><body>Hello World!</body></html>\r\n"
我尝试创建一个 test.rb 文件,将其放在公共目录中,然后像http://localhost:3000/test.rb一样调用它,但这似乎不起作用。它认为我正在尝试下载文件。我在这里想念什么?小脚本如下:
#!/usr/local/bin/ ruby
print "HTTP/1.0 200 OK\r\n"
print "Content-type: text/html\r\n\r\n"
print "<html><body>Hello World!</body></html>\r\n"
有一个小型的 http 守护程序服务器用于此类事情。我从未听说您可以配置任何浏览器来为您执行脚本,因此您可能会遇到与我类似的设置:
您可以在sourceforge找到 shttpd(现在称为 mongoose,从外观上看)。我用于 ruby 应用程序的配置文件如下所示:
# SHTTPD web server configuration file.
# Lines starting with '#' and empty lines are ignored.
# For detailed description, visit http://shttpd.sourceforge.net/shttpd.1.txt
#platform-specific stuff
root c:\main\src\worker\http
systray no
access_log logs\shttpd_access_log.txt
error_log logs\shttpd_error_log.txt
cgi_env RUBYLIB=c:\main\src\worker;c:\main\src\worker\lib
cgi_interp c:\InstantRails\ruby\bin\ruby.exe
#platform-dependant stuff
ports 2001
cgi_ext rb
threads 5
index_files index.rb
如果您有任何进一步的问题,只需更新,我会尽量关注线程。