加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

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

发布时间:2020-12-13 20:58:56 所属栏目:Nginx 来源:网络整理
导读:更新:目前,我在domain.com:3000上访问我的应用程序,但是我想访问domain.com来查看我的应用程序 我在80处设置了nginx以在3000处代理我的rails应用程序.以下是配置 upstream railsapp { server 127.0.0.1:3000;}server { listen 80; server_name APP; # Tell

更新:目前,我在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;
}

现在一切正常!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读