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

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

我想使用 Nginx 为我的 Rails(使用 passenger)和 Angular 前端提供服务。

基本上,所有发送到 / 的请求都应定向到 Rails,而发送到 /admin/* 的每个请求都应重定向到 Angular 应用程序。

我发现 question 理论上这正是我要找的东西。不幸的是,对于对 Nginx 了解不多(几乎一无所知)的人(比如我)来说,Dmitry 的回答有点含糊。

编辑:这是我尝试过的 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;
    }

}

有人可以扩展一下答案吗?

谢谢!

我认为 haproxy 这是一个更好的工具。

但我在 standalone passenger server 中有一些 rails 应用程序,前面是 nginx。

我建议的 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>;
  }
}