Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Redirect 为什么使用Nginx执行SSL的重定向在某些浏览器中失败?_Redirect_Ssl_Nginx - Fatal编程技术网

Redirect 为什么使用Nginx执行SSL的重定向在某些浏览器中失败?

Redirect 为什么使用Nginx执行SSL的重定向在某些浏览器中失败?,redirect,ssl,nginx,Redirect,Ssl,Nginx,我有一个节点应用程序,它带有两个服务器进程。一个提供我的应用程序本身,另一个提供API。我使用Nginx作为反向代理,通过443(和80)提供代理请求,并通过人工端点向API发出代理请求 我对nginx Docker容器进行了以下设置: 一般配置: user nginx; worker_processes 5; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { wor

我有一个节点应用程序,它带有两个服务器进程。一个提供我的应用程序本身,另一个提供API。我使用Nginx作为反向代理,通过443(和80)提供代理请求,并通过人工端点向API发出代理请求

我对nginx Docker容器进行了以下设置:

一般配置:

user  nginx;
worker_processes  5;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
以及HTTP和HTTPS的特定服务器部分:

server {
  listen 80;

  server_name mydomain.de;
  access_log /var/log/nginx/nodejs_project.log;
  charset utf-8;

  rewrite_log on;

  return 301 https://$server_name$request_uri;
}

server {
  listen 443 ssl;

  server_name mydomain.de;
  access_log /var/log/nginx/nodejs_project.log;
  charset utf-8;

  rewrite_log on;

  ssl_certificate     /etc/nginx/bundle.pem;
  ssl_certificate_key /etc/nginx/webserver.key;

  location / {
    proxy_pass http://mydomain:8080;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

  location /api {
    rewrite  ^/api/(.*) /$1 break;
    proxy_pass http://mydomain:3030;
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}
目标是自动将所有HTTP请求重定向到HTTPS。这就是,当我卷曲页面时会发生什么:

→ curl -IL mydomain.de
HTTP/1.1 301 Moved Permanently
Server: nginx/1.9.15
Date: Sat, 21 May 2016 12:26:12 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: https://mydomain.de/

HTTP/1.1 302 Found
Server: nginx/1.9.15
Date: Sat, 21 May 2016 12:26:13 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 30
Connection: keep-alive
X-Powered-By: Express
Location: /steps/1
Vary: Accept, Accept-Encoding

HTTP/1.1 200 OK
Server: nginx/1.9.15
Date: Sat, 21 May 2016 12:26:13 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 39705
Connection: keep-alive
X-Powered-By: Express
ETag: W/"9b19-576TRcOW5QU6nLaobx28iw"
Vary: Accept-Encoding
我觉得很好。首先是从HTTP到HTTPS的301,然后是由应用程序本身触发的302

这在大多数浏览器中都有效,但也有少数浏览器失败。尤其是Windows上的Firefox、iOS上的Chrome和其他一些浏览器,当我尝试加载时,它们什么也不做:
mydomain.de
甚至
http://mydomain.de

证书没问题。它不是自行签署的,而是由RapidSSL发行的。该捆绑包包括CA的根证书、中间证书以及我的服务器证书,按照文档的顺序排列。正确重定向的浏览器不会对此抱怨。当我通过
直接加载页面时,失败的浏览器不会抱怨证书https://mydomain.de

我甚至尝试添加:

add_header Strict Transport Security“最大年龄=63072000;
包括子域;
预加载”


但这让情况变得更糟。有人能告诉我,我的错误在哪里吗?

查看浏览器控制台(即开发人员工具)是否有任何错误,并查看浏览器执行的请求以及它们停止工作的确切位置(也包括开发人员工具)。您能否尝试将“return 301 https://$host$request_uri”放在重定向中并添加“proxy_redirect http://https://;”在位置块/?Thx@FromBabylon中。至少我有权使用浏览器来工作。我会尽快检查列表的其余部分,但显然是添加了这两个配置行使其工作。查看浏览器控制台(即开发人员工具)是否有任何错误,查看浏览器执行的请求以及它们停止工作的确切位置(也包括开发人员工具)。能否尝试将“return 301 https://$host$request_uri”放入重定向中,并添加“proxy_redirect http://https://;”在位置块/?Thx@FromBabylon中。至少我有权使用浏览器来工作。我将尽快检查列表的其余部分,但显然是添加了这两个配置行才使其工作。