我们在一台服务器上安装了常规网站(http://example.com
)和网络邮件(https://example.com/mail
)、Debian、Joomla、NGINX 和 iRedMail。
为了防范 DDoS,我们使用免费版 CloudFlare。
所以问题是:当关闭 CF 时,一切都正常 - 网站和网络邮件都可以访问。但是当打开 CF 保护时 - 网站正常,但网络邮件在 SSL 中显示“重定向次数过多”。
尝试按照描述进行设置这里- 没有什么变化。
似乎是 CF 规则或 ngnix 中的重定向规则配置错误 - 无法理解。但是在哪里?
/etc/nginx/sites-enabled/example.com
(网站):
server {
listen 80;
server_name example.com;
server_name_in_redirect off;
root /var/www/example.com;
index index.php index.html index.htm default.html default.htm;
location / {
try_files $uri $uri/ /index.php?$args;.
}
location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
return 403;
error_page 403 /403_error.html;
}
location ~* \.(ico|pdf|flv)$ {
expires 1y;
}
location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
expires 14d;
}
include /etc/nginx/templates/php-catchall.tmpl;
include /etc/nginx/templates/redirect_to_https.tmpl;
include /etc/nginx/templates/misc.tmpl;
}
/etc/nginx/sites-enabled/example.com_443
(网络邮件):
server {
listen 443;
server_name mail.example.com;
ssl on;
ssl_certificate /etc/ssl/certs/iRedMail.crt;
ssl_certificate_key /etc/ssl/private/iRedMail.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-R
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/dh2048_param.pem;
index index.php index.html;
location / {
root /opt/www/roundcubemail;
}
# Web applications.
include /etc/nginx/templates/roundcube.tmpl;
include /etc/nginx/templates/iredadmin.tmpl;
include /etc/nginx/templates/php-catchall.tmpl;
include /etc/nginx/templates/misc.tmpl;
}
CF 规则:
https://example.com/mail SSL:Flexible - Full
启用 CF 保护时example.com
(DNS A 记录) mail.example.com
会陷入重定向循环。
答案1
问题出在 cloudflare 服务的 DNS 记录上。情况如下:
...
example.com. 300 IN A 1.2.3.4
www 300 IN A 1.2.3.4
mail 300 IN A 1.2.3.4
...
将 A 记录更改为 CNAME,如下所示:
...
example.com. 300 IN A 1.2.3.4
www.example.com. 300 IN CNAME example.com.
mail.example.com. 300 IN CNAME example.com.
...
做了那件事。