ruby-on-rails-如何配置Nginx代理到Rails应用程序?这样我就不必说domain.com:port

更新:目前,我在domain.com:3000上访问我的应用程序,但是我想访问domain.com来查看我的应用程序我在80处设置了nginx以在3000处代理我的rails应用程序.以下是配置upstream railsapp {server 127.0.0.1:3000;}server ...

更新:目前,我在domain.com:3000上访问我的应用程序,但是我想访问domain.com来查看我的应用程序
我在80处设置了nginx以在3000处代理我的rails应用程序.以下是配置

upstream railsapp {
  server 127.0.0.1:3000;
}

server {
  listen 80;
  server_name APP;

  # Tell Nginx and Passenger where your app's 'public' directory is
  root /var/www/APP/current/public;
  index index.html index.htm;

  # Static assets are served from the mentioned root directory
location / {
    root /var/www/APP/current;
    index index.html index.htm;

    proxy_pass http://railsapp/;
    proxy_redirect off;
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    # proxy_set_header X-Real-Port $server_port;
    # proxy_set_header X-Real-Scheme $scheme;
    proxy_set_header X-NginX-Proxy true;
}

  # Turn on Passenger
  passenger_enabled on;
  passenger_ruby /usr/local/rvm/gems/ruby-2.1.3/wrappers/ruby;
}

我指的是:
https://stackoverflow.com/a/5015178/1124639

它位于/etc/nginx/sites-enabled/APP.conf中,并包含在/etc/nginx/nginx.conf中,如下所示,位于http {…}中

include /etc/nginx/sites-enabled/*;

但是我的APP.com仍然显示“欢迎使用Ubuntu上的nginx!” APP.com:3000显示了我的应用.我究竟做错了什么?

我正在使用什么:
Ubuntu 14.04 EC2实例
nginx 1.8.0
麒麟服务器3000

解决方法:

我试图运行独角兽,以便可以将我的应用程序分叉到多个实例.我猜这里的问题是,我将passenger_enabled设置为on,并且实际上是在3000上运行独角兽.

所以我跑了乘客

passenger start -a 127.0.0.1 -p 3000 -d -e production

和我的Nginx conf这样,

server {
listen 80;
server_name www.APPNAME.com;

# Tell Nginx and Passenger where your app's 'public' directory is
root /var/www/APPNAME/current/public;
index index.html index.htm;

# Static assets are served from the mentioned root directory
location / {
#  root /var/www/APPNAME/current;
#  index index.html index.htm;
proxy_pass http://127.0.0.1:3000;

proxy_redirect off;
proxy_set_header X-Real-IP  $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
# proxy_set_header X-Real-Port $server_port;
# proxy_set_header X-Real-Scheme $scheme;
proxy_set_header X-NginX-Proxy true;
}

# Turn on Passenger
passenger_enabled on;
passenger_ruby /usr/local/rvm/gems/ruby-2.1.3/wrappers/ruby;
}

现在一切正常!

本文标题为:ruby-on-rails-如何配置Nginx代理到Rails应用程序?这样我就不必说domain.com:port

基础教程推荐