WagnerMatosUK
WagnerMatosUK

Reputation: 4429

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.

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.

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.

EDIT: Here's the Nginx configuration that I have tried:

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!

Upvotes: 1

Views: 1000

Answers (1)

Javier Valencia
Javier Valencia

Reputation: 695

I think haproxy it's a better tool to do this.

But I have some rails apps in standalone passenger server with nginx in front.

My suggested nginx config:

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>;
  }
}

Upvotes: 1

Related Questions