如何为 rails 应用程序指定网址? [英] How to specify a web address to a rails application?
问题描述
我使用的是 Ubuntu 12.04 并且我有一个 Rails 应用程序,我想在启动时启动它.此外,如果我从控制台启动服务器,如
I am using Ubuntu 12.04 and I have a rails application, that I would like to start on boot. Also if I start the server from console like
cd <path of the application>
rails s -p 3000
我必须保持控制台打开,否则应用程序将在我结束终端后立即结束.
I will have to keep the console open, else the application will end as soon as I end the terminal.
第二次访问应用程序时,我必须访问 localhost:3000.我更愿意在浏览器中使用像 localhost/myapp 这样的专有名称或只是 myapp 来访问它.
Second to access the application I will have to access localhost:3000. I would rather like to have access it with a proper name like localhost/myapp or just myapp in browser.
首先,有可能吗?我该怎么做?
First, is it possible? How do I do that?
PS:我已经有一些 PHP 应用程序在 Apache 上运行.我不想弄乱默认的 80/8080 端口.
PS: I already have some PHP applications running on Apache. I would not like to mess with the default 80 / 8080 port.
推荐答案
编辑 /etc/hosts
以添加
127.0.0.1 myapp
此外,如果您不想在浏览器中指定 3000 端口,请从 rails s -p 80
开始.这可能会干扰已经在侦听 80 端口的 Apache 进程.
Also, start with rails s -p 80
if you don't want to specify the 3000 port in the browser. This can interfere with an Apache process already listening to the 80 port.
使其与 Apache 一起工作:
EDIT : To make it work with Apache :
让 Rails 应用打开 3000 端口并为 Apache 启用 mod proxy
,以便 ProxyPass
请求传入 myapp
主机.
Let the Rails app on the 3000 port and enable mod proxy
for Apache, in order to ProxyPass
requests incoming to the myapp
host.
这里有几个例子:httpd.apache.org/docs/2.0/mod/mod_proxy.html
There is several examples here : httpd.apache.org/docs/2.0/mod/mod_proxy.html
这篇关于如何为 rails 应用程序指定网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!