防止Nginx移除端口号

那么,我真的很困惑。 我有一个虚拟机内运行nginx的Web服务器。 我正在从主机端口8082到虚拟机中的端口80。 事实上,去exampledomain.dev:8082按预期显示的网页。

当我input一个类似于exampledomain.dev:8082/subdirectory的url时,问题就会发生

浏览器将我redirect到没有端口号的exampledomain.dev/subdirectory ,所以没有任何工作。 但是,如果我像在这个exampledomain.dev:8082/subdirectory/中的URL中添加反斜杠,它正常工作。

我的问题是,我怎么能指出exampledomain.dev:8082/subdirectoryexampledomain.dev:8082/subdirectory/到同一个地方,以及如何防止nginx删除端口号?

如果是重要的,这是我在虚拟机内的实际nginxconfiguration:

 server { listen 80; server_name exampledomain.dev; root /srv/www/exampledomain; index index.php; rewrite ^([^.]*[^/])$ $1/ permanent; location /subdirectory { try_files $uri $uri/ /subdirectory/index.php?$args; } } 

最简单的解决办法是改变你的重写

 rewrite ^([^.]*[^/])$ http://exampledomain.dev:8082/$1/ permanent;