小编Nxt*_*xt3的帖子

在 port_in_redirect: off 之后 NGINX 重定向到 HTTP

最近,如果 URL 缺少尾部斜杠(例如:https://example.com/thing将重定向到https://example:8080/thing/),我在重定向后放置端口号时遇到了问题。所以,我添加了一行port_in_redirect off;,解决了这个问题。然而,它现在引起了另一个问题。如果 url 缺少尾部斜杠,它会重定向到 HTTP。

https://example.com/thing将重定向到http://example/thing/,这会导致请求失败。

这是我的 nginx.conf 的样子:

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
error_log  /var/log/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    log_format logstash_json '{ "@timestamp": "$time_iso8601", '
                          '"@fields": { '
                          '"remote_addr": "$remote_addr", '
                          '"remote_user": "$remote_user", '
                          '"request": "$request", '
                          '"status": "$status", ' …
Run Code Online (Sandbox Code Playgroud)

nginx redirect

3
推荐指数
1
解决办法
4310
查看次数

标签 统计

nginx ×1

redirect ×1