Rails:如何配置NGINX + Passenger以同时服务于静态站点和Rails应用程序

时间:2019-04-09 16:05:27

标签: passenger nginx-config

我在Passenger NGINX集成模式下有一个带有Rails 6应用程序的AWS Ubuntu实例:

server {
  listen 80;
  listen [::]:80;
  server_name _;
  root /home/ubuntu/railsapp/public;
  passenger_enabled on;
  passenger_app_env production;
  location /cable {
    passenger_app_group_name railsapp_websocket;
    passenger_force_max_concurrent_requests_per_process 0;
  }
  client_max_body_size 100m;
  location ~ ^/(assets|packs) {
    expires max;
    gzip_static on;
  }
} 

我想挤在一个点击率不高的静态网站上。一个人,它的配置是:

server {
    listen 80;
    server_name static.site;
    root /home/ubuntu/static;
    index index.html index.htm;
    location / {
      try_files $uri $uri/ =404;
    }  
  }
}

所以我尝试将它们结合起来。静态站点可以,但是Rails应用无法正常工作(504超时):

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}
server {
    listen 80;
    server_name railsapp.site
    root /home/ubuntu/railsapp/public;
    passenger_enabled on;
      passenger_app_env production;
      location /cable {
        passenger_app_group_name railsapp_websocket;
        passenger_force_max_concurrent_requests_per_process 0;
      }
      client_max_body_size 100m;
      location ~ ^/(assets|packs) {
        expires max;
        gzip_static on;
      }
    location / {
        proxy_pass http://0.0.0.0:3000;
        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_buffering off;
    }
}
server {
    listen 80;
    server_name static.site;
    root /home/ubuntu/static;
    index index.html index.htm;
    location / {
      try_files $uri $uri/ =404;
    }  
  }
}

如何为旅客+ NGINX上的Rails和静态站点提供服务?

0 个答案:

没有答案