Nginx+HTTP2+HTTPS 环境搭建

准备

下载以下依赖

  • libressl 
    > 在滴血事件之后,作为OpenSSL的替代
  • zlib
  • pcre

以上内容不需要自行make,通过nginx一并manke。 
为后续升级方便,相关依赖解压缩到/opt,建立没有版本号的软连接

Nginx安装

./configure –prefix=/opt/nginx –user=forever –group=forever –with-http_stub_status_module –with-http_v2_module –with-http_ssl_module –with-openssl=/opt/libressl –with-ipv6 –with-http_gzip_static_module –with-http_realip_module –with-http_flv_module –with-pcre=/opt/pcre –with-zlib=/opt/zlib 
make && make install

安装完成之后会在/opt/nginx安装内容。

生成HTTPS证书

  • 生成私钥Key 
    openssl genrsa -aes256 -out private/test.chehejia.com.key.pem 2048
  • 生成证书请求(向第三方认证机构申请) 
    openssl req -new -key private/test.chehejia.com.key.pem -out private/test.chehejia.com.key.csr -subj “/C=CN//ST=BJ/L=BJ/O=CHJ/OU=NET/CN=test.chehejia.com” 
    把csr文件提交证书机构进行申请。

  • 生成自签发证书 
    openssl req -new -x509 -key openssl.key -out openssl.crt -days 3650

Nginx部署

在conf/nginx.conf中编辑https

  1. # HTTPS server
  2. server {
  3. listen 443 ssl http2 default_server;
  4. server_name localhost;
  5. ssl_certificate private/test.chehejia.com.crt;
  6. ssl_certificate_key private/test.chehejia.com.key;
  7. ssl_session_cache shared:SSL:1m;
  8. ssl_session_timeout 5m;
  9. ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:AES256+EECDH:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4';
  10. ssl_prefer_server_ciphers on;
  11. location / {
  12. root html;
  13. index index.html index.htm;
  14. }
  15. }

启动验证

cd $NGINX_HOME 
sbin/nginx

猜你喜欢

转载自xiaonanforever.iteye.com/blog/2284556