0

I have a CMS instance that has its Admin panel hard-coded at /admin(https://example.com/admin) and it can't be changed by CMS. I thought to try Nginx to carry this task. CMS runs as a Nodejs app and served by proxy_pass.

location / {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    add_header X-Cache $upstream_cache_status;
    proxy_connect_timeout 30s;
    proxy_read_timeout 86400s;
    proxy_send_timeout 30s;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";

    proxy_pass http://localhost:8000;
}

Would it be possible to replace https://example.com/admin with https://example.com/custom using Nginx only? Any advice is highly welcome as I don't understand where to start here.

P.S. If it matter CMS is Directus.

Upd. I tried to use Nginx reverse proxy + URL rewrite but it didn't help. Here are my attempts:

location /foo {
  rewrite /foo/(.*) /admin/$1 break;
  proxy_pass localhost:8000;
  proxy_redirect off;
  proxy_set_header Host $host;
}

gave me /foo => /foo/admin/login?redirect=/foo/

location /foo {
  rewrite /foo/(.*) /$1 break;
  proxy_pass localhost:8000/admin;
  proxy_redirect off;
  proxy_set_header Host $host;
}

gave me /foo => /admin/foo

5
  • Does this answer your question? Nginx reverse proxy + URL rewrite
    – djdomi
    Nov 14 at 18:16
  • I couldn't apply. Tried this ` location /foo { rewrite /foo/(.*) /admin/$1 break; proxy_pass localhost:8000; proxy_redirect off; proxy_set_header Host $host; } ` and received this URI foo/admin/login?redirect=/foo/ Tried this ``` location /foo { rewrite /foo/(.*) /$1 break; proxy_pass localhost:8000/admin; proxy_redirect off; proxy_set_header Host $host; } ``` And git this URI admin/foo
    – vogdb
    Nov 14 at 18:33
  • Comments don't allow multiline code blocks, sorry.
    – vogdb
    Nov 14 at 18:35
  • don't use commentary section to respond changes, please update the question instead please
    – djdomi
    Nov 15 at 18:51
  • updated the question
    – vogdb
    Nov 15 at 19:06

0

You must log in to answer this question.

Browse other questions tagged .