Reputation: 3632
I have the following configuration for nginx
location /discord/ {
rewrite ^/discord/(.*) /$1 break;
proxy_pass http://127.0.0.1:8086/;
proxy_pass_header Cookie;
port_in_redirect off;
proxy_set_header Host $host;
}
location / {
proxy_pass http://127.0.0.1:8089/;
proxy_pass_header Cookie;
proxy_set_header Host $host;
}
As you can see , I have two servers running on the same domain The question is:
I have a link inside http://127.0.0.1:8086/ . Let's say I want to visit default page , I open this link http://domain/discord then I press the link in this page with path '/test' and I go to the following page http://domain/test but I want to visit this page http://domain/discord/test
How can I configure Nginx to add discord prefix to urls inside http://127.0.0.1:8086/ page
Upvotes: 0
Views: 601
Reputation: 190
What you try to do here, is trying to make the rewrite rules redirect visitors to different location based on the previous path
This will need the web server understand the referer request header which can only be implemented from application layer (eg. PHP) but not server configurations in my understanding
An approach is to use the relative path on the links, for example:
Root document (rewritten by web server) under
http://domain/discord/
Absolute path:
href="/test"
=>http://domain/test
Relative path:
href="./test"
=>http://domain/discord/test
You can change the location to rewrite in nginx in future and won't effect to relative paths
Root document (rewritten by web server) under
http://domain/telegram/
Absolute path:
href="/test"
=>http://domain/test
Relative path:
href="./test"
=>http://domain/telegram/test
Upvotes: 1