為二級域名註冊ssl證書,並強制使用https對http進行跳轉
阿新 • • 發佈:2018-12-13
伺服器上仍然使用nginx進行代理
1.為二級域名申請ssl證書,如blog.yourdomain.com,見前文。
2.在域名解析服務中,為二級域名新增解析記錄
3.nginx預設讀取/etc/nginx/conf.d/*.conf
在conf.d下建立二級域名對應的配置檔案如vi blog.conf
upstream ech{ server ip:port; #此處最好指定內網ip } server{ listen 80; server_name ech.domain.cn; #此處指定子域名訪問 location/ { proxy_pass http://ech; } }
這樣,一個簡單的http二級域名就實現了,但是由於在nginx中,對所有http服務都做了重定向至https,所以需要在配置https的配置檔案。
4.配置完成如下:
upstream blog{ server 10.139.xxx.xxx:8090; #此處指定的雲伺服器內網ip } server{ listen 80; rewrite ^(.*)$ https://$host$1 permanent; location / { #proxy_pass http://blog; } } server{ listen 443 ssl http2 ; server_name blog.yourdomain.cn; #此處指定子域名訪問 ssl_certificate "/home/ssl/keys/blog.yourdomain.cn/1_blog.yourdomain.cn_bundle.crt"; ssl_certificate_key "/home/ssl/keys/blog.yourdomain.cn/2_blog.yourdomain.cn.key"; ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { tcp_nodelay on; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://10.139.xxx.xxx:8090; } }