Nginx,重定向后在url中保存位置路径

Nginx,重定向后在url中保存位置路径,nginx,Nginx,我对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:808

我对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;
  }
如您所见,我有两台服务器在同一个域上运行 问题是:

我在中有一个链接。假设我想访问默认页面,我打开了这个链接 然后我按下此页面中带有路径“/test”的链接,进入下一页,但我想访问此页面


如何将Nginx配置为将discord前缀添加到页面中的URL

将'discord/test'作为href添加到链接中。

您尝试在此处执行的操作是,尝试使重写规则根据前面的路径将访问者重定向到不同的位置

这将需要web服务器理解,它只能从应用层(例如PHP)实现,但在我的理解中不能从服务器配置实现


一种方法是使用链接上的相对路径,例如:

http://domain/discord/

绝对路径:
href=“/test”
=>
http://domain/test

相对路径:
href=“./test”
=>
http://domain/discord/test

以后可以在nginx中更改要重写的位置,但不会影响相对路径

http://domain/telegram/

绝对路径:
href=“/test”
=>
http://domain/test

相对路径:
href=“./test”
=>
http://domain/telegram/test


如果将来我想将/discord更改为/telegram,那么我必须在nginx config和服务器路由中重写它。应该通过nginx完成,而不是通过端口8086上的web服务器