Nginx HTTP到HTTPS 301循环重定向

时间:2019-03-22 05:55:47

标签: nginx https http-status-code-301

我需要对整个站点进行HTTP-> HTTPS重定向,但是每次我收到带有301循环重定向的错误消息时。请更正我的配置文件以免出现301错误。这是我的配置文件:

upstream live {
  server IP:PORT;
  }
server {
      listen      80 default;
      server_name mysite.com;
      access_log  off;
      error_log   off;
      root /usr/share/nginx/html/;
      index index.html index.htm;
      return 301 https://$host$request_uri;
}
server {
      listen 443;
      root /usr/share/nginx/html/;
      index index.html index.htm;
      rewrite_log on;
      server_name mysite.com;
      access_log /var/log/nginx/access.log;
      error_log /var/log/nginx/error.log debug;
      client_max_body_size 200m;

      location / {
        index index.html index.htm;
      try_files $uri $uri/ /index.html?$uri&$args;
      }

      location /web {
        proxy_pass https://live/gateway/web;
        proxy_set_header "MP_FRONT" aaa;
        proxy_pass_request_headers      on;
      }
}

enter image description here

1 个答案:

答案 0 :(得分:0)

只需尝试替换如下所示的第一个服务器JSON

server {
    listen 80;
    listen [::]:80 default_server ipv6only=on;
    server_name example.com;
    return 301 https://www.example.com$request_uri;
}

请尝试让我知道它是否对您有用