Rails Nginx:多个应用程序

帕维尔·巴宾(Pavel Babin)

我为应用程序提供了两个Nginx配置:

1)Rails应用

upstream app {
  server unix:/home/deploy/railsapp/shared/tmp/sockets/puma.sock fail_timeout=0;
}

server {
  listen 80;
  server_name api.example.com;

  root /home/deploy/railsapp/current/public;

  try_files $uri/index.html $uri @app;

  location / {
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Connection '';
    proxy_pass http://app;
  }

  location ~ ^/(assets|fonts|system)/|favicon.ico|robots.txt {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

2)静态html / js应用程序

server {
  listen 81;
  server_name  client.example.com;
  root /home/deploy/clientapp;

  location / {
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Connection '';
   # proxy_pass http://app;
  }

  location ~ ^/(assets|fonts|system)/|favicon.ico|robots.txt {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }
}

问题是这两个地址api.example.comapi.example.com打开相同的应用程序(api.example.com

马丁·卡斯特(Martijn Casteel)

一些关于nginx config的基础教程;https://www.digitalocean.com/community/tutorials/how-to-configure-the-nginx-web-server-on-a-virtual-private-server您应该对Rails应用程序使用代理,而不对静态html应用程序使用代理

server {
  listen 80; #should also be 80
  server_name  client.example.com;

  root /home/deploy/clientapp;
  index index.html index.htm;

  location / {
     try_files $uri $uri/ /index.html;
  }

  location ~ ^/(assets|fonts|system)/|favicon.ico|robots.txt {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }
}

要测试您可以执行的配置,是否nginx -t应该nginx -s reload使用新配置重新加载如前所述,此问题与rails无关,它只是nginx配置。

会根据server_name请求返回哪个网站,如果没有default_server,它将返回加载到nginx配置中的最后一个网站。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为多个Rails应用程序配置NGINX

使用Nginx映射Rails应用程序

RAILS应用程序中的多个API

使用Nginx + Unicorn在子文件夹上托管多个Rails应用程序

使用Nginx和Unicorn的多个Rails应用程序的一个域名

使用 rails 应用程序安装 ssl 证书的 nginx 配置

无法访问 Nginx 的 Ruby on Rails 应用程序

基于Docker的Rails应用程序的nginx维护页面

Nginx支持的Rails应用程序缺少内容长度标题

使用Rails应用程序和Vue.js应用程序设置Nginx + Passenger

在rails应用程序中从多个模型创建pdf文件

用于多个Rails应用程序的heroku memcachier

在Rails应用程序中为多个模型使用devise

从 Ruby on Rails 5 API 应用程序渲染多个图像

让我们加密“ Welcome to Nginx”的Nginx而不是Rails应用程序

Nginx - 多个应用程序

Rails应用程序的内存最佳设置(在Phusion乘客/ nginx上)

部署Rails API ONLY应用程序时是否需要使用Nginx?

在Vagrant / VirtualBox / nginx Rails应用程序的主机OSX 127.0.0.1:3000上拒绝连接

Amazon EC2的端口80上的Rails应用程序-使用Nginx或IpTables

如何将开发模式Rails应用程序与Nginx服务器连接?

Rails + 乘客 + Nginx:第二个应用程序的“404 Not Found”

使用Nginx和Puma在Ruby on Rails应用程序上启用SSL

为什么Nginx的乘客在我的Rails应用程序中寻找passenger_wsgi.py

ElasticBeanstalk和Rails-部署应用程序但未找到404(未找到)nginx / 1.4.3

如何使用Puma和Nginx配置在子URL上托管的Rails 3应用程序?

使用Capistrano,nginx,puma将Rails应用程序部署到DigitalOcean

尝试访问Rails控制台时git remotes中有多个应用程序

如何将Ruby on Rails 5应用程序拆分为多个文件夹?