我想避免重复nginx中的所有虚拟主机服务器块,只是为了让自定义ssl设置与普通的http请求略有不同。
大多数SSL指令可以放在主块,除了一个障碍,我找不到一个解决方法:不同的保持活着的https和http
有什么办法可以使用$scheme来dynamic改变keepalive_timeout吗?
我甚至认为我可以使用more_set_input_headers -r 'Keep-Alive: timeout=60'; 有条件地取代保活超时只有当它已经存在,但问题是$scheme不能在location即使用。 这是无效的location ^https {}
我很确定你可以使用map :
map $scheme $myCustomTTL { default 90; http 90; https 60; } add_header Keep-Alive timeout=$myCustomTTL;
由于似乎keepalive_timeout不能用于参数,但只能用于固定值,另一种解决scheme是使用nginx作为SSL端点。
您的SSL请求将由特定的server{}块处理,该块只会pipe理SSL握手和特定的Keep-Alive值,然后将纯HTTP请求转发到主server {}块。
你的nginxconfiguration将包含如下内容:
upstream plain_http { server 127.0.0.1:80; } server { listen 443; server_name *.yourdomain.com; ssl on; ssl_certificate /etc/nginx/ssl/mycert.pem; ssl_certificate_key /etc/nginx/ssl/mykey.key; ssl_protocols SSLv3 TLSv1; ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM; ssl_prefer_server_ciphers on; keepalive_timeout 90; location / { proxy_pass http://plain_http; proxy_redirect http:// https://; } }
proxy_redirect伪指令告诉nginx重写plain-HTTP响应中的Location和Refresh标头中的URI。