NGINX卡在服务器上的HTTPS重定向中

时间:2019-05-14 04:05:32

标签: nginx

我一直在尝试在服务器上设置自签名证书(因为当您访问IP时,不是某些域,因为我没有链接任何域)。我遵循了某些教程,并使用openssl编写了一个教程,并将文件放在这里。 ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt; ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;

然后我在/etc/nginx/snippets/self-signed.conf中创建了一个配置片段,如下所示。

ssl_protocols TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/nginx/dhparam.pem;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0
ssl_session_timeout  10m;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off; # Requires nginx >= 1.5.9
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
# Disable strict transport security for now. You can uncomment the following
# line if you understand the implications.
# add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";

之后,我刚刚创建了一个ssl-params.conf,其中包含以下内容:

/etc/nginx/sites-available/default

最后,由于我没有服务器块,因此将配置放在server { listen 80 default_server; listen [::]:80 default_server; # SSL configuration listen 443 ssl default_server; listen [::]:443 ssl default_server; include snippets/self-signed.conf; include snippets/ssl-params.conf; return 302 https://$host$request_uri; location ~ / { proxy_set_header X-Forwarded-Proto $scheme; } } 中 我拿的是一个简单的。

{{1}}

但是现在每当我访问服务器的IP时,都会出现重定向过多次的问题。我似乎找不到我做错了什么,因此将不胜感激。

1 个答案:

答案 0 :(得分:1)

server {listen 443 ssl;

    server_name  localhost;


    ssl_certificate     D:/yourcertificate.crt;
    ssl_certificate_key D:/yourcertificate.key;




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

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

  location / {
   # proxy_set_header   X-Real-IP $remote_addr;
   proxy_set_header   Host      $http_host;
   proxy_pass         http://localhost:8080;
}}

按照此链接https://youtu.be/ikbN1bYnBjg进行更好的理解。