我正在尝试做以下的事情
当我访问www.example.com时,出现了太多的redirect错误。 当我去到example.com,它工作正常。
不知道我错了哪里。 下面是我的服务器块代码。
server { server_name example.com www.example.com; return 301 https://www.example.com$request_uri; } server { server_name www.mydomain.com ... }
以下是我如何redirect到https://www.example.com
server { server_name www.example.com; listen 443 ssl http2; ssl_certificate /var/lib/acme/certs/***CERT_DIRECTORY/fullchain; ssl_certificate_key /var/lib/acme/certs/***CERT_DIRECTORY/privkey; # Set up preferred protocols and ciphers. TLS1.2 is required for HTTP/2 ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5; // locations etc } # This server simply redirects the requested to the https version of the page server { listen 80; server_name example.com www.example.com; return 301 https://www.example.com$request_uri; } server { listen 443 ssl http2; server_name example.com; ssl_certificate /var/lib/acme/certs/***CERT_DIRECTORY/fullchain; ssl_certificate_key /var/lib/acme/certs/***CERT_DIRECTORY/privkey; # Set up preferred protocols and ciphers. TLS1.2 is required for HTTP/2 ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5; return 301 https://www.example.com$request_uri; }