【问题标题】:Alter Nginx.conf file to route to rails project更改 Nginx.conf 文件以路由到 rails 项目
【发布时间】:2013-11-08 10:06:35
【问题描述】:

好的,这是我的第一个 vps,这是我的 hello world 测试。我离展示我的 Rails 应用程序只有一步之遥

我有一个运行 Ubuntu 的 VPS。

我有一个 Rails 项目就坐在这里:

(我使用 git 从 git hub 中提取它,然后运行 ​​'bundle install' 在 vps 上安装 gem,根本没有使用 Capistrano)

root /home/starkers/rails_application ->

test_app

当我在浏览器中访问我的 vps 的 IP 时,我会收到 Welcome to nginx! 页面。

最后,

sudo nano /opt/nginx/conf/nginx.conf

打开我的配置文件。

现在,大约一个小时内我还没有在这方面取得任何进展。所有在线指南都显示了稍微不同的 nginx.conf 结构,所以我在这里有点摸不着头脑。

nginx.conf 文件非常大,我需要更改哪些变量才能向服务器路由直接发送 http 请求到 rails 项目?

我认为这对我的目的很重要:

  server {
    listen       80;
    server_name  localhost;

        #charset koi8-r;
 #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
   }

如果有人能多向我解释一下,我将不胜感激。我打赌这里引用的 index.html 是“欢迎使用 nginx!”页。公共网络服务器是否应该始终侦听端口 80? server_name 重要吗?

然后我如何调整 nginx.conf 文件,以便我购买的 url 将路由项目?

真的不介意在这里提供帮助。

【问题讨论】:

  • 您打算从这个 vps 托管多个网站吗?如果没有,您可以将要使用的域名添加到上面的server_name。另外,您是否考虑过应用服务器?我推荐passenger gem

标签: ruby-on-rails ubuntu nginx


【解决方案1】:

这确实是一个多步骤的过程。您需要:

  1. 为要从中托管应用的域配置 nginx 服务器块。
  2. 在 Rails 应用程序和 nginx 之间配置应用程序服务器或其他“桥梁”。我会推荐乘客宝石。

如果你决定走乘客路线,你可以像下面这样修改上面的服务器块:

passenger_root /somewhere/passenger-x.x.x;
passenger_ruby /usr/bin/ruby;
passenger_max_pool_size 10;
server {
    # uncomment the line below if you will be serving multiple domains/websites from this box
    # server_name example.com www.example.com;
    listen 80;

    # point this to the path to your rails app's public directory
    root /home/starkers/rails_application/test_app/public;

    passenger_enabled on;
}

来源:http://www.modrails.com/documentation/Users%20guide%20Nginx.html

这个HOW TO install guide from digitalocean may be of interest to you

【讨论】:

    猜你喜欢
    • 2018-04-14
    • 1970-01-01
    • 2017-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-24
    相关资源
    最近更新 更多