我该如何去有关服务器上设置我的西纳特拉REST API? [英] How do I go about setting up my Sinatra REST API on a server?

查看:174
本文介绍了我该如何去有关服务器上设置我的西纳特拉REST API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名iOS开发者为主。在构建我目前的应用程序,我需要一个能与一对夫妇的GET请求的REST API的服务器。我花了一点时间来学习Ruby和着陆使用辛纳屈,一个简单的web框架。我可以运行我的服务器脚本,通过浏览器访问它在本地主机:4567 ,与当时的要求是本地主机:4567 /你好,作为一个例子

在此处,我觉得我的深度。我在设置一个DigitalOcean Ubuntu的液滴,觉得我的路绕到通过命令行设置所有必要的工具,直到我能再次运行我的服务器,现在这滴。

问题则是,我不能再通过 droplet.ip.address访问我的服务器:4567 ,以及一些研究使我发现我需要的乘客和Apache HTTP服务器是设置和<一个href=\"https://www.digitalocean.com/community/tutorials/how-to-deploy-sinatra-based-ruby-web-applications-on-ubuntu-13\"相对=nofollow>不是用简单的说明。

我是方式在我头上这里,我感觉不舒服。必须有一个更好的办法,我把我的小群红宝石文件,并在服务器上运行这一点,比我这样做。但我不知道我在做什么。

任何帮助或建议将不胜AP preciated。


解决方案

  

研究位使我发现我需要乘客和Apache HTTP服务器进行设置,而不是简单的指令。


忽略现在。先取婴儿的步骤。您应该能够从上DigitalOcean液滴在命令行中运行你的应用程序西纳特拉,然后通过访问droplet.ip.address:4567 。如果不起作用的东西很基本的错误。

当您启动应用程序,你会看到应用程序被监听的地址和端口。请确保它是 0.0.0.0 和4567如果是 127.0.0.1 本地主机这意味着它只会在同一台机器发起服务请求

在你得到这个工作,下一步是让你的应用程序西纳特拉到服务。从本质上讲,这意味着在后台的应用程序运行,并自动启动,当系统重新启动。考虑主管这是非常简单的配置得到这个运行。

之后,您可以安装Apache或Nginx的把你的应用程序西纳特拉的前面。这些代理它只是向前从端口80(默认HTTP端口)要求您西纳特拉应用程序,但可以做更多的事情,如添加SSL支持,负载平衡,自定义错误页等等 - 这一切你并不需要现在。

I'm an iOS developer primarily. In building my current app, I needed a server that would have a REST API with a couple of GET requests. I spent a little time learning Ruby, and landed on using Sinatra, a simple web framework. I can run my server script, and access it from a browser at localhost:4567, with a request then being localhost:4567/hello, as an example.

Here's where I feel out of my depth. I setup an Ubuntu droplet at DigitalOcean, and felt my way around to setting up all necessary tools via command line, until I could again run my server, now on this droplet.

The problem then is that I couldn't then access my server via droplet.ip.address:4567, and a bit of research lead me to discovering I need Passenger and an Apache HTTP Server to be setup, and not with simple instructions.

I'm way in over my head here, and I don't feel comfortable. There must be a better way for me to take my small group of ruby files and run this on a server, than me doing this. But I have no idea what I'm doing.

Any help or advice would be greatly appreciated.

解决方案

bit of research lead me to discovering I need Passenger and an Apache HTTP Server to be setup, and not with simple instructions.

Ignore that for now. Take baby steps first. You should be able to run your Sinatra app from the command line on the DigitalOcean droplet, and then access it via droplet.ip.address:4567. If that doesn't work something very fundamental is wrong.

When you start your app, you will see what address and port the app is listening on. Make sure it's 0.0.0.0 and 4567. If it's 127.0.0.1 or localhost that means it will only service requests originating from the same machine

After you get this working, next step is to make your Sinatra app into a service. Essentially this means the app runs in the background, and auto-starts when the system reboots. Look into Supervisor which is very simple configuration to get this running.

Later you can install Apache or Nginx to put in front of your Sinatra app. These are proxies which simply forward requests from port 80 (default HTTP port) to your sinatra app, but can do additional things such as add SSL support, load balancing, custom error pages etc. - all of which you do not need right now.

这篇关于我该如何去有关服务器上设置我的西纳特拉REST API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆