Docker nginx/traefik 301 将 http 重定向到本地主机上的 https

2024-03-17

这是后续关闭 Docker 中的 https https://stackoverflow.com/questions/67087945/turn-off-https-in-docker还有一些更多信息。我还没想明白。

我在 Docker slack 小组中询问,他们确信它来自 nginx 或 traefik 配置。

在 Firefox 中,存在 SSL_ERROR_UNRECOGNIZED_NAME_ALERT 错误,在 Chrome 中,存在类似的 ERR_SSL_UNRECOGNIZED_NAME_ALERT。我通过搜索并没有找到太多关于其中任何一个的信息。

我的 nginx 配置:

user                                    nginx;
daemon                                  off;
worker_processes                        auto;
error_log                               /proc/self/fd/2 debug;

events {
  worker_connections                  1024;
  multi_accept                        on;
}

http {
  include                             /etc/nginx/mime.types;
  default_type                        application/octet-stream;
  fastcgi_buffers                     16 32k;
  fastcgi_buffer_size                 32k;
  fastcgi_intercept_errors            on;
  fastcgi_read_timeout                900;
  include                             fastcgi_params;
  access_log                          /proc/self/fd/1;
  port_in_redirect                    off;
  send_timeout                        600;
  sendfile                            on;
  client_body_timeout                 600;
  client_header_timeout               600;
  client_max_body_size                256M;
  client_body_buffer_size             16K;
  client_header_buffer_size           4K;
  large_client_header_buffers         8 16K;
  keepalive_timeout                   60;
  keepalive_requests                  100;
  reset_timedout_connection           off;
  tcp_nodelay                         on;
  tcp_nopush                          on;
  server_tokens                       off;
  upload_progress                     uploads 1m;

  gzip                                on;
  gzip_buffers                        16 8k;
  gzip_comp_level                     2;
  gzip_http_version                   1.1;
  gzip_min_length                     20;
  gzip_types                          text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/x-icon application/vnd.ms-fonto
  gzip_vary                           on;
  gzip_proxied                        any;
  gzip_disable                        msie6;

  add_header                          X-XSS-Protection '1; mode=block';
  add_header                          X-Frame-Options SAMEORIGIN;
  add_header                          X-Content-Type-Options nosniff;

  map $http_x_forwarded_proto $fastcgi_https {
      default $https;
      http '';
      https on;
  }

  map $uri $no_slash_uri {
      ~^/(?<no_slash>.*)$ $no_slash;
  }


  upstream backend {
      server php:9000;
  }


  include conf.d/*.conf;
}

我的 nginx.conf.default:

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/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"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

我的 docker-compose.yml 与上一个问题相比没有变化。

我一直在寻找类似 traefik 配置的东西,但找不到任何东西。

到目前为止我尝试过的事情:

  • 交换里面的东西map $http_x_forwarded_proto $fastcgi_https i.e. default $http; http on; https '';
  • 删除整个地图块
  • 删除 docker-compose.yml 第 140 行中对 https 的引用
  • 从 docker-compose.yml 中删除第 143 行
  • 从 docker-compose.yml 中删除第 147 行
  • 为本地主机创建自签名证书
  • 麻布和灰烬

我真的很茫然,感谢任何帮助。


经过 OP 的更多测试以及其他用户的评论:看来重定向(HTTP 到 HTTPS)是在 Nginx 处理请求后发生的。

OP 还使用单个 index.html 文件进行了测试,并且没有重定向到 HTTPS:确认重定向来自 PHP(或者至少不是来自 Nginx)。

接下来的步骤是研究 Drupal 配置和/或 htaccess 配置。 OP更改了一些Drupal配置(关于重定向),并成功使drupal设置页面仅使用HTTP。

在这种情况下,最好的方法是始终尝试查明问题的根源:

  • 使您的 Nginx 配置最少:简单的index.html
  • 定期清除浏览器缓存:它们有时会缓存重定向
  • 检查/删除 htaccess 以查看行为是否发生变化
  • 最后,如果 Nginx 没有任何问题,并且 htaccess 似乎不是问题:它主要是“之后”,所以问题可能来自“Nginx 向谁发送请求”
  • 从 Drupal、Woocommerce、Laravel 等“大型”框架/CMS 中...重定向通常可以从配置文件或数据库设置“轻松”处理。
  • 当您有处理重定向的自定义代码时:它需要调试
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Docker nginx/traefik 301 将 http 重定向到本地主机上的 https 的相关文章

随机推荐

  • python 多线程连接超时

    看起来 如果你有一个n个线程的循环 并将它们与超时t逐一连接 那么你实际花费的时间是n t 因为开始计算一个子线程的超时时间是最后一个子线程的结束时间 有什么办法可以将总时间减少到 t 而不是 n t 吗 是的 您可以计算绝对超时 并在每次
  • 跟踪集合的旧部分和新部分

    我正在使用backbone js 并且我有一个包含 dos 的集合fetch 有时 我不想通过该选项 add true 由于我的子视图的创建方式 集合被循环 每个项目都是附加到当前表的新行 我尝试的一件事就是清空整个表并创建所有新行 但这太
  • 为 Web 表单添加自定义基类

    我想为我的所有 Web 表单添加自定义基类 我在我的 asp net web 项目中创建了一个 App code 文件夹 并添加了一个简单的基页面类 如下所示 namespace MySite Web base page for all t
  • 打包Python项目时设置zip_safe为True有什么好处?

    setuptools 文档仅说明 为了获得最佳性能 Python 包最好安装为 zip 文件 然而 并非所有包都能够以压缩形式运行 因为它们可能期望能够像正常操作系统文件一样访问源代码或数据文件 因此 setuptools 可以将您的项目安
  • 无法以编程方式在外部存储上创建文件夹 - Android

    这是我的代码 boolean success false Log d TAG Environment getExternalStorageDirectory Environment DIRECTORY PICTURES myFolder m
  • 在浏览器中使用 NodeJS Crypto 模块和 webpack

    我正在编写一个 javascript REPL 旨在在浏览器中运行并执行 nodejs 加密函数 我的项目是在 ReactJS 中 我使用 webpack 将所有模块和依赖项捆绑在一起 我试图将内置节点加密模块包含在 webpack 生成的
  • TypeScript 到 JSDoc:全局/接口

    我目前正在使用 JSDoc 将项目从 TypeScript 转换为 JavaScript 我正在尝试使用 JSDoc 执行以下操作 declare global namespace jest interface Matchers
  • ld:找不到 -lz.1.2.3 的库

    当尝试编译适用于 iOS 5 的软件时 XCode 4 2 抛出错误 ld library not found for lz 1 2 3 我发现这篇文章告诉我替换 1 2 3 与 1 2 5 https github com dbloete
  • Flexslider - 图像预加载器

    我的响应式 flexslider 插件有问题 除非实际幻灯片中有很多图像 否则该插件可以正常工作 那么加载行为是不可接受的 我希望有人可以帮助我使用以下 flexslider 图像预加载器脚本 因为我无法让它工作 这是我正在使用的代码 柔性
  • 在 R Shiny 标头中制作图像超链接

    我一直在尝试将图像输出超链接到网站 但我在仔细阅读有关堆栈溢出的其他问题时遇到了麻烦 带有闪亮的可点击链接的 svg 不可点击 https stackoverflow com questions 37121767 svg with clic
  • Html5 的文件 API - BLOB 用法?

    我有一个文件输入 jsbin http jsbin com atICecog 4 edit
  • 如何修复在多人或组字段中添加用户时 SharePoint 中的错误(仅限人员)

    我正在尝试在 Sharepoint 列表中的多人或组字段 仅限人员 中添加多个用户 但我收到以下错误消息 从 JSON 读取器读取时发现意外的 PrimitiveValue 节点 预期是 StartObject 节点 我已使用 REST 调
  • Rails 应用程序移至生产服务器时出现“符号转储格式错误”错误

    我刚刚将 Rails 应用程序从开发服务器移至部署服务器 我已经安装了乘客 但我想尝试一下rails s确保一切运行良好 这是我第一次开发和部署 Rails 应用程序 规格为 带有 RVM mod passenger Rails 3 2 3
  • WCF发送大量数据

    我想将大量数据发送到 WCF 服务 数据可能由数千个 od 记录 实体 组成 具体取决于解析的输入文件 现在的问题是 发送这些数据的最佳方式是什么 A 逐条记录 通过这个 我将确保我不会超过允许的最大消息大小 并且我可以从 las 成功发送
  • pandas.read_clipboard 来自云托管的 jupyter?

    我正在服务器上运行 JupyterHub 的 Data8 实例 并运行 JupyterLabpd read clipboard 似乎不起作用 我在谷歌colab中看到同样的问题 import pandas as pd pd read cli
  • 具有固定不均匀行的 HTML 表格

    I m creating a page that allows the user to select a time slot from a schedule I would prefer to do this with some sort
  • PhoneRTC 64 位支持吗?

    PhoneRTC http phonertc io 目前不支持 64 位设备 从2015年2月1日起 Apple 要求所有 iOS 应用程序支持 64 位设备 https developer apple com news id 102020
  • 最严格的 C 代码的 GCC 选项? [复制]

    这个问题在这里已经有答案了 应该设置哪些 GCC 选项以使 GCC 尽可能严格 我的意思是尽可能严格 我正在用 C89 编写并希望我的代码符合 ANSI ISO 兼容 我建议使用 Wall Wextra std c89 pedantic W
  • 如何在属性选择器中使用/模拟类似正则表达式的反向引用?

    我想要做的是编写一个在一个地方匹配任意值的选择器 然后要求一个不同的值与其相等 如果 attr value 将 值 解析为正则表达式 那么这将解决我的问题 class class if 1 styles 显然 我可以单独列出每个可能的类 但
  • Docker nginx/traefik 301 将 http 重定向到本地主机上的 https

    这是后续关闭 Docker 中的 https https stackoverflow com questions 67087945 turn off https in docker还有一些更多信息 我还没想明白 我在 Docker slac