Nginx-配置https虚拟服务(访问http时自动跳转https)
https口令文件和nginx配置文件位置关系:
nginx配置文件内容如下:
#user nobody; worker_processes 1; #设置工作进程数 pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; #gzip on; #配置集群1 upstream upstream_name1(可使用域名) { server ip:port; } #配置集群2 upstream upstream_name2(可使用域名) { server ip:port; } #配置集群3 upstream upstream_name3(可使用域名) { server ip:port; } # 配置http虚拟主机,会自动跳转到https服务 [测试使用8081作为http port] server { listen 8081; server_name nginx域名:8081; #监听nginx所在服务器8081端口 rewrite ^(.*) https://nginx域名:8082$1 permanent; } # 配置https虚拟主机,[测试使用8082作为https port] server { listen 8082 ssl; server_name nginx域名:8082; #监听nginx所在服务器8082端口 #ssl on; ssl_certificate ssl/server_wildcard.cer; #此处配置https的口令文件 ssl_certificate_key ssl/server_wildcard.key; #此处配置https的密钥文件 ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { root html; index index.html index.htm; } location /server1/ { #路由访问路径server1到集群1 proxy_pass http://upstream_name1; proxy_redirect default; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 2000; } location /server2/ { #路由访问路径server2到集群2 proxy_pass http://upstream_name2; proxy_redirect default; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 2000; } location /server3/ { #路由访问路径server3到集群3 proxy_pass http://upstream_name3; proxy_redirect default; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 2000; } } }