Docker ngix/traefik 301 将 http 重定向到 localhost 中的 https [英] Docker ngix/traefik 301 redirecting http to https in localhost

查看:85
本文介绍了Docker ngix/traefik 301 将 http 重定向到 localhost 中的 https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在 Docker 中关闭 https 的后续内容,提供更多信息.我还没弄明白.

This is a follow up to Turn off https in Docker with some more information. I still haven't figured it out.

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

I asked in the Docker slack group and they are convinced it's coming from the nginx or traefik config.

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

In Firefox there is a SSL_ERROR_UNRECOGNIZED_NAME_ALERT error, and in Chrome it's the similar ERR_SSL_UNRECOGNIZED_NAME_ALERT. I'm not finding out much about either of those by searching.

我的 nginx 配置:

My nginx config:

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:

My 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 与上一个问题没有变化.

My docker-compose.yml is unchanged from the previous question.

我找了一个类似于 traefik 配置的东西,但找不到任何东西.

I've looked for anthing resembling traefik config and can't find anything.

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

Things I've tried so far:

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

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

I'm genuinely at a loss, any help appreciated.

推荐答案

经过 OP 的更多测试和其他用户的评论:似乎在 Nginx 处理请求后发生了重定向(HTTP 到 HTTPS).

After more tests from OP, and other user's comments: it seemed that the redirection (HTTP to HTTPS) was occurring after Nginx handled the request.

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

OP also tested using a single index.html file and was not redirected to HTTPS: confirming that the redirection came from PHP (or at least not from Nginx).

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

The next steps were to look into Drupal configuration, and/or htaccess configuration. OP changed some Drupal configuration (about redirections), and successfully got the drupal setup page working with HTTP only.

在这种情况下,最好始终尝试找出问题的来源:

Best in those case is always to try to pin-point the where the issue come from:

  • 使您的 Nginx 配置最小化:简单的 index.html
  • 定期清除浏览器缓存:他们有时会缓存重定向
  • 检查/删除 htaccess 以查看行为是否发生变化
  • 最后,如果 Nginx 是干净的"来自任何问题,而 htaccess 似乎不是问题:它主要是之后",所以问题可能来自Nginx 向谁发送请求"
  • 来自大"框架/CMS,如 Drupal、Woocommerce、Laravel……重定向通常容易"处理;来自配置文件或数据库设置.
  • 当您有自定义代码处理重定向时:需要调试

这篇关于Docker ngix/traefik 301 将 http 重定向到 localhost 中的 https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆