我希望在我的重写中动态保持ServerName和Port:
假设防火墙将端口8081重定向到80。
因此,如果我使用“192.168.1.123/frontend”或“my.domain.tld:8081/frontend”访问Web服务器,则应重定向到“192.168.1.123/frontend/”或“my.domain.tld:8081/frontend/”。
如果我使用普通的
我几乎使用默认配置:
如果我使用普通的
redirect rewrite ^(.*[^/])$ $1/ permanent;
并访问端口8081,则会删除端口。(我已经尝试过port_in_redirect off;
)我几乎使用默认配置:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
rewrite ^(.*[^/])$ $1/ permanent;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
感谢您的期待!
解决方案: 感谢NGINX邮件列表! 我用重写规则解决了这个问题:
if (-d $request_filename) {
rewrite [^/]$ $scheme://$http_host$uri/ permanent;
}