新手问题 如何独立开启 Ruby WebServer, 访问静态目录

lilijreey · 2016年04月13日 · 最后由 darkbaby123 回复于 2016年04月15日 · 3112 次阅读

以前使用 nginx 可以在浏览器中访问根目录 我现在有个目录,希望开启一个单独的 webServer, 然后可以在浏览器中通过 webServer 来访问,这个目录里的所有文件。 怎么做?最好能自动生成目录页面。 还有那位大牛能给一些 Rack 配置文件的资料。感谢

用 Nginx 就好了

@fsword 谢谢 参数的解释 Obviously, ruby is the normal Ruby interpreter. The -r switch requires a file in the load path, in this case Ruby’s lib directory. In this case, it’s loading a file called un.rb so that it looks like -run when taken as a whole. (It could be written as -r un as well.) This is similar to ubygems.rb which you may have seen as ruby -rubygems. That seems like an ugly solution, but it’s elegant in its own way. This naming hack is only really an option for files in Ruby itself, anyway. As you can see above, httpd is just a method, which is executed by -e. The DocumentRoot argument . is just taken as a standard argument using ARGV, which I found surprising. Finally, the port is set using the setup method, which in turn calls out to the built in OptionParser.

http://www.benjaminoakes.com/2013/09/13/ruby-simple-http-server-minimalist-rake/

python -m SimpleHTTPServer

gem install Rwebserver
Rwebserver

gem "asdf"

仅一个方法

module Asdf
  class Server < ::Rack::Server
    def app
      Rack::Directory.new(Dir.pwd)
    end
  end
end

ruby -run -e cp -- [OPTION] SOURCE DEST ruby -run -e ln -- [OPTION] TARGET LINK_NAME ruby -run -e mv -- [OPTION] SOURCE DEST ruby -run -e rm -- [OPTION] FILE ruby -run -e mkdir -- [OPTION] DIRS ruby -run -e rmdir -- [OPTION] DIRS ruby -run -e install -- [OPTION] SOURCE DEST ruby -run -e chmod -- [OPTION] OCTAL-MODE FILE ruby -run -e touch -- [OPTION] FILE ruby -run -e wait_writable -- [OPTION] FILE ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION] ruby -run -e httpd -- [OPTION] DocumentRoot ruby -run -e help [COMMAND] 这个 un.rb 名字起得真怪

不止 Ruby,很多语言都有简单启动 server 的方法。Google 一下 one line server。或者看 这个链接

需要 登录 后方可回复, 如果你还没有账号请 注册新账号