0

I'm using a reverse Proxy in order to run two applications on the same port by using Nginx. This is my Nginx conf file.

server{
  
        listen 80;
        location / {
         proxy_pass "http://127.0.0.1:8081";
        }
        location /admin {
         rewrite ^/admin(.*) $1 break;
         proxy_pass "http://127.0.0.1:8085";
        }
}

My Angular app running on port 8085 is not handling the rerouting with /admin right. Meaning if I don't specify any header, it works fine (just like in this example) :

server{
  
        listen 80;
        location / {
         proxy_pass "http://127.0.0.1:8085";
        }
        location /admin {
         rewrite ^/admin(.*) $1 break;
         proxy_pass "http://127.0.0.1:8081";
        }
}

But not with /admin header.

So, I changed my Routes object in my app-routing.module.ts from :

const routes: Routes = [
  {path: '', redirectTo: 'users', pathMatch :'full'},
  { path: 'users', component: ListUsersComponent },
  { path: 'users/:id', component: UserDetailsComponent },
  {path: 'add', component: AddUserComponent}
];

To:

  const routes: Routes = [
      {path: 'admin', redirectTo: 'admin/users', pathmatch: 'full'},
      { path: 'users', component: ListUsersComponent },
      { path: 'users/:id', component: UserDetailsComponent },
      {path: 'add', component: AddUserComponent}
    ];

(I also tried different path configurations like :

   const routes: Routes = [
      {path: 'admin', redirectTo: 'admin/users', pathmatch: 'full'},
      { path: 'admin/users', component: ListUsersComponent },
      { path: 'admin/users/:id', component: UserDetailsComponent },
      {path: 'admin/add', component: AddUserComponent}
    ];

and many more)

No matter what I get this error in my console.

GET http://XX.XX.XXX.XX/main.XXXXXXXXX.js net::ERR_ABORTED 404 (Not Found)

Am I doing something wrong ?

2
  • Why do you need a rewrite? Take a look on my working example with the routing: stackoverflow.com/questions/68724761/… Also /admin is not a "header". You can check your nginx with the external utility (like curl) that it works correctly. Commented Dec 1, 2021 at 16:55
  • Check this answer. Commented Dec 1, 2021 at 17:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.