将我的 http://网站重定向到 https://网站不起作用

问题描述 投票:0回答:1

我想将我们网络服务器的所有流量重定向到 https。我们正在使用 nginx 运行一个 docker 容器。

从服务器内部检查我的重定向时,它似乎正在执行重定向

$ curl -L -I  http://maxquant.org
HTTP/1.1 301 Moved Permanently
Server: nginx/1.19.10
Date: Tue, 21 Nov 2023 08:12:10 GMT
Content-Type: text/html
Content-Length: 170
Connection: keep-alive
Location: https://maxquant.org/

HTTP/1.1 200 OK
Server: nginx
...

但是当我输入 http://maxquant.org (带或不带 www)时,我得到标准 nginx 响应(欢迎来到 Nginx ...),一切都很好,但重定向不起作用。

我不确定,我还需要在 docker/nginx 设置中更改什么才能使重定向起作用。

docker的配置如下所示。参数

${NGINX_DOMAIN}
.env
文件中说明。

nginx.conf.模板

server {
  listen 80;

  server_name ${NGINX_DOMAIN};

  return 301 https://$host$request_uri;
}
server {
  listen 443 ssl default_server;
  server_name ${NGINX_DOMAIN};

  gzip              on;
  ...

  location / {
     include uwsgi_params;
     uwsgi_pass maxquant_download_app:8001;
  }

  location /static {
      root /app/maxquant;
  }

  location /p/ {
      secure_link $arg_md5,$arg_expires;
      secure_link_md5 "$secure_link_expires$uri ${NGINX_SECRET}";

      if ($secure_link = "") {
          return 403;
      }

      if ($secure_link = "0") {
          return 410;
      }
      rewrite ^/p/(.*)$ /assets/$1;
   }

   location /assets/ {
       internal;
       root /app/maxquant;
   }
}

docker-compose.yml

version: '3.4'
services:
  maxquant_download_app:
    ...     
  nginx:
    container_name: nginx
    build:
      context: ..
      network: host
      dockerfile: docker/nginx.dockerfile
      args:
      ...
  depends_on:
    - maxquant_download_app
    ports:
      - 80:80
      - 443:443
    restart: "always"

[编辑:] 使用 http 给我标准的 Nginx 欢迎页面,而不是请求的网站:

docker nginx redirect https
1个回答
0
投票

我给出建议作为答案(没有足够的声誉来发表评论)

对 NGINX 配置文件进行更改后,请记住重新加载 NGINX 以应用更改:

sudo nginx -s reload
© www.soinside.com 2019 - 2024. All rights reserved.