nginx怎么配置ssl

nginx怎么配置ssl

假設在擁有了ssl證書的情況下:

直接上代碼如下:

server?{????????listen?443;????????server_name?www.domain.com;?#填寫綁定證書的域名 ????????ssl?on;????????ssl_certificate?1_www.domain.com_bundle.crt;????????ssl_certificate_key?2_www.domain.com.key;????????ssl_session_timeout?5m;????????ssl_protocols?TLSv1?TLSv1.1?TLSv1.2;?#按照這個協議配置 ????????ssl_ciphers?ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照這個套件配置 ????????ssl_prefer_server_ciphers?on;????????location?/?{????????????root???html;?#站點目錄 ????????????index??index.html?index.htm; ????????} ????}

上面代碼就配置了www.domain.com, 現在你就可以通過https://www.domain.com?來訪問了.

配置反向代理:

server?{????????listen?443;????????server_name?blog.domain.com;?#填寫綁定證書的域名 ????????ssl?on;????????ssl_certificate?blog.domain.com_bundle.crt;????????ssl_certificate_key?blog.domain.com.key;????????ssl_session_timeout?5m;????????ssl_protocols?TLSv1?TLSv1.1?TLSv1.2;?#按照這個協議配置 ????????ssl_ciphers?ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照這個套件配置 ????????ssl_prefer_server_ciphers?on;????location?/?{????????????????proxy_pass?http://localhost:81;????????????????proxy_redirect?off;????????????????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_next_upstream?error?timeout?invalid_header?http_500?http_502?http_503?http_504;????????????????proxy_max_temp_file_size?0;????????????????proxy_connect_timeout?90;????????????????proxy_send_timeout?90;????????????????proxy_read_timeout?90;????????????????proxy_buffer_size?4k;????????????????proxy_buffers?4?32k;????????????????proxy_busy_buffers_size?64k;????????????????proxy_temp_file_write_size?64k; ????} }

如上就配置了https 反向代理。

由于國內免費的ssl證書都是單域名證書因此每次配置時候都是需要重新制定證書。

全站加密

編輯nginx.conf 文件,在ubuntu上的位置在于:?/etc/nginx/nginx.conf

http?{????#?沈略部分 ????server?{????????rewrite?^(.*)?https://$host$1?permanent; ????} }

上面代碼即可進行從http 自動跳轉到https 上,從而實現全站加密。

更多Nginx相關技術文章,請訪問Nginx教程欄目進行學習!

? 版權聲明
THE END
喜歡就支持一下吧
點贊10 分享