Rails + passenger + nginx使用url运行app而不使用:port

时间:2013-02-18 14:56:08

标签: ruby-on-rails nginx passenger

我有一个rails应用程序...我安装了链:nginx + passenger并运行rails服务器。但我的麻烦是在浏览器中我必须设置网址:

page.com:3000

但如何仅使用page.com?

我无法运行用户限制的命令passenger start -e=development -p=80 ....

我的nginx配置文件是这样的:

server {
        listen      80;
        server_name  localhost;

        #charset koi8-r;
        #root /home/prog/OnlineAuto/Shop/public;
        #passenger_enabled on;
        #access_log  logs/host.access.log  main;
        location / {
                root /home/prog/OnlineAuto/Shop/public;
                index  index.html index.htm;
                passenger_enabled on;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

那么如何在没有任何端口的情况下通过域获取我的rails应用程序? (但在3000端口上运行rails服务器)

2 个答案:

答案 0 :(得分:1)

你试图在Nginx使用的同一个端口上启动Passenger,这可能是你收到错误的原因。

我对Unicorn更熟悉,但根据我读过的文档,您不必在单独的过程中启动Passenger。正确安装Passenger后,我认为您只需要Nginx指令即可使其正常工作。

nginx.conf的http块中配置您的passenger_root和passenger_ruby,然后

http {
  passenger_root /<path_to_passenger_install>;
  passenger_ruby /usr/local/bin/ruby;

  server {
    listen 80;
    server_name page.com;
    charset utf-8;
    root /www/page.com/public;
    passenger_enabled on;
    rails_spawn_method smart;
    rails_env development;
  }
}

答案 1 :(得分:0)

如果您在这里使用乘客,我必须使用它才能在www.mysite.com上使用它,而无需在centos服务器上使用www.mysite.com:80:

在etc / httpd / conf中,密钥是取消注释NameVirtualHost *:80并将*更改为我服务器的IP地址。确保取消注释Listen 80。还要将您的IP添加到VirtualHost标记。它必须在端口80上运行,而不是8080或您选择的东西。

NameVirtualHost xx.xx.xx.xx:80  

Listen 80  

<VirtualHost xx.xx.xx.xx:80>
    ServerName www.mysite.com
    # !!! Be sure to point DocumentRoot to 'public'!
    DocumentRoot /var/www/vhosts/mysite.com/httpdocs/public/
    <Directory /var/www/vhosts/mysite.com/httpdocs/public/>
       # This relaxes Apache security settings.
       AllowOverride all
       # MultiViews must be turned off.
       Options -MultiViews
    </Directory>
</VirtualHost>