简体   繁体   English

如何配置Nginx在同一域上同时服务Rails应用程序和Angular

[英]How to configure Nginx to serve both Rails app and Angular on same domain

I'd like to use Nginx to serve both my Rails (using passenger) and an Angular front end. 我想使用Nginx来服务我的Rails(使用乘客)和Angular前端。

Basically, all requests that goes to / should be directed to Rails and every request that goes to /admin/* should be redirected to a Angular App. 基本上,所有发送到/请求都应定向到Rails,每个发送到/admin/*请求都应重定向到Angular App。

I've found this question that would theoretically be exactly what I'm looking for. 从理论上讲,我已经找到了这个问题 Unfortunately Dmitry's answer is a bit vague for someone (like me) who doesn't know much (next to nothing) about Nginx. 不幸的是,德米特里(Dmitry)的答案对于像我这样对Nginx不太了解(几乎不了解)的人有点含糊。

EDIT: Here's the Nginx configuration that I have tried: 编辑:这是我尝试过的Nginx配置:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name 178.62.92.199;
    passenger_enabled on;
    passenger_app_env development;
    root /var/www/netturing/public;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location ~ ^/admin/ {
            proxy_pass http: /var/www/client/admin;
    }

    location / {
            proxy_pass http: /var/www/netturing/public;
    }

}

Could someone extend the answer a bit? 有人可以扩大答案吗?

Thanks! 谢谢!

I think haproxy it's a better tool to do this. 我认为haproxy是执行此操作的更好工具。

But I have some rails apps in standalone passenger server with nginx in front. 但是我在独立的乘客服务器中有一些Rails应用,前面有nginx。

My suggested nginx config: 我建议的Nginx配置:

server {

  # some config directives
  ...

  # Al turrón !

  # Angular App
  location ~ ^/admin/ {
    proxy_pass http://<URI TO ANGULAR APP>;
  }

  # Rails App
  location / {
    proxy_pass http://<URI TO RAILS APP>;
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何设置Apache以在同一DocumentRoot上同时提供Rails应用程序和完整的PHP应用程序 - How to setup apache to serve both a rails app and a full php app at the same DocumentRoot 如何配置Apache以在同一台计算机上同时提供RoR和Flask? - How to configure apache to serve both RoR and Flask on the same machine? 如何配置nginx在域中使用Rails应用程序,在/ blog /中使用WordPress? - How do I configure nginx to have a Rails app at a domain and WordPress at /blog/? 如何将Rails应用的Nginx配置为子域? - How configure nginx for rails app as subdomain? 如何在我的Rails 4应用程序中配置Compass和Zurb Foundation 5,以便它们都可以在同一目录中访问? - How can I configure Compass and Zurb Foundation 5 in my Rails 4 app so that they are both accessible in the same directory? 如何在Rails应用程序下为域提供html树? - How can I serve a tree of html for a domain under a Rails app? 为多个Rails应用程序配置NGINX - Configure NGINX for multiple rails app 如何配置nginx在SubURI上提供gitlabhq - How to configure nginx to serve gitlabhq on a SubURI 如何在Rails Box上使用Nginx代理Angle App? - How to proxy angular app with nginx on a rails box? nginx-如何在域中没有应用名称的情况下创建Rails应用 - nginx - how to create rails app without app name in domain
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM