nginx循环redirect在清漆ssl实现

我正在尝试在我的ssl enalbled网站上实施清漆。 但我正在获得循环redirect。 这就是我要去的地方

清漆在港口80听;

DAEMON_OPTS="-a :80 \ -T localhost:6082 \ -f /etc/varnish/default.vcl \ -S /etc/varnish/secret \ -s malloc,256m" 

和后端

 backend default { .host = "127.0.0.1"; .port = "8080"; .connect_timeout = 16s; .first_byte_timeout = 96s; .between_bytes_timeout = 8s; 

}

nginx正在8080上运行。 nginxconfiguration

 upstream backend { ip_hash; server 127.0.0.1:80; # IP goes here. } server { listen 443 ssl; server_name example.com www.example.com; root /var/www/test/public; index index.php; ssl_certificate /var/www/ascacacaa1341.crt; ssl_certificate_key /var/www/www.example.com.key; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { try_files $uri $uri/ /index.php?$query_string; proxy_pass http://backend; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Port 443; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $host; proxy_set_header X-Secure on; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/test/public$fastcgi_script_name; } location /var/www/test/public { autoindex on; autoindex_exact_size off; } # We don't need .ht files with nginx. location ~ /\.htaccess { deny all; } # Set header expirations on per-project basis location ~* \.(?:ico|css|js|jpe?g|JPG|png|svg|woff)$ { expires 365d; } } server { listen 8080; server_name example.com www.example.com; return https://$server_name$request_uri; } tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 30700/nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 30479/varnishd tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 30700/nginx tcp 0 0 127.0.0.1:6082 0.0.0.0:* LISTEN 30475/varnishd tcp6 0 0 :::80 :::* LISTEN 30479/varnishd 

curl反应curl -I -k https://www.domain.com

 HTTP/1.1 302 Moved Temporarily Server: nginx/1.6.2 Date: Mon, 03 Nov 2014 10:38:31 GMT Content-Type: text/html Content-Length: 160 Connection: keep-alive Location: https://www.domain.com/ X-Varnish: 623340 361289 Age: 280 Via: 1.1 varnish-v4 

它确实适用于ssl。 代理redirect不起作用。 我正在redirect到清漆所在的80端口。 但是我仍然得到循环redirect。 从检查我发现net :: ERR_TOO_MANY_REDIRECTS。 错误。 任何人谁可以帮助这里。 我有更多的域和子域在同一台服务器。 但是我不会只在ssl域上实现清漆。

问题在那里:

 server_name www.example.com example.com ... location / { rewrite ^ https://$server_name$request_uri permanent; } 

您正在对端口8080上的域www.example.comexample.com请求进行响应,并将其redirect到www.example.com因为server_name将始终与第一个server_name值匹配,而您愿意响应https请求example.com

所以改变那个服务器块到:

 server { listen 8080; server_name example.com www.example.com; return https://$server_name$request_uri; } 

顺便说一句,当你不需要它时,停止使用rewrite / regex。