标签:rgb bar oiv gad vhd tms pyc bash man
Nginx是一款应用非常广泛的web服务软件,具有轻量级、扩展性好、跨平台、动态加载配置文件等特点。同时具有反向代理、负载均衡等功能,深受IT技术人员青睐。生产环境一般都是购买的商业版SSL证书,常见品牌有赛门铁克、geotrust、global sign、沃通等,不同的品牌性能和价格方面都会有一定的差距,比较受欢迎的就是通配符证书,例如*.baidu.com * 代表任意字符串 一个证书可以用于多个子域名。本文主要是将自己配置Nginx https证书的过程记录。没那么奢侈购买商业产品。将会分享一下自制SSL证书以及Nginx配置SSL证书的过程。
Nginx实现https需要http_ssl_module模块支持,该模块是默认编译模块,不需要我们再次编译。
一、制作证书
1、生成key文件
openssl genrsa -out cert.key 2048
key文件内容
-----BEGIN RSA PRIVATE KEY----- MIIEoQIBAAKCAQEAxFtXu3n1TMDSVw7E5YlIY0EMORJMyalBWejs7f9gTBT0rc2v vB7u4qqf2bFi/HGf7a28GEDKJdkn9HAV9fHYM4efFoZbAary+CGjoMQKEnk8EA0a kWoCIY7unz8Zvo82CffCXHHFMmzCBuPXXj5bXF7uWqRELD6AGbJiGeCK4R4jDvXv EP7mgRd6uR7uF0aFUCYvy5c2OZ/I4dyHG/D1zfkbjQ0DXknRWYr31Ahao1wxri3D cEe8i37a22Nq2NPlEibqtYXDQF5D3sZBJT2oRPkQSBlI9SqXfqvLy/nqYeG9IpKd St48JUClgVLsvdG/vkGTj09R/arik9wVoqfgFQIDAQABAoH/B6uJwckBy/28Oapa Bp1WNopT7+bHGRmDc/+lQaa4HEC1ThS6yJ5stm3z0I0dUL8fgClJL6lYPCI/bUzz jqfjyh+CF18oLuh+lTK7MYx22EHkFrxsTUHW03jB2XaditQNSFZlQTcwfMfCzIIZ 55SH/RO4O9Iu14uZdWeCbYBX7HMvY2b+GRHLNeXGDsLnctaNP90/1DnWMPDKM+Ep l9DUrfMQf1IL/BKilA9k2wE6eI7eI14t8/7Q0mlSOIrgTti6Ep9TU2pCLkSkS2hu VKGqNqMZpN4rn+2lmKGr/LXjtM7BNeUHBM1jFBsZTs+KgU1oy66GjLIebB1km1Yw UE45AoGBAOnHKgsgjrW8by8tGFlGvxN/4ILUPzmuSwmybCweoezLzHuFtWAHS013 pM0uMMK5CmrC4t0vlw3rPycpgYjModPAL/cXVBHOcJQeA29DFh1cSODi4DckJtPD +T0ZHOaAWpuaSeBNXOS89ToVZKfr1TYhPQgIsbYHTpA5tjnKz6DbAoGBANcFjvC7 pimZW+ZLISkKVDxfOOgExvHd1TuEs87kRC+HzMfKSbUgu3M2gHmboj7vyRt+3F4J A2aA1aOCLDKs5GAvbMG+b4iXpW4l43ItWtutwcHMcQU04zZNK7IPecYC4bqq3D81 EI2oehQH2ImJMe2BFewA8uW9Ldl6qxf+ZB3PAoGAdA9EeDG5p8/dAvbIV8ofonah 51Gn8eLtreq+eUjb6stiwRAoc3wrjlIPpy1/V6y11zrZliXCQE7CE5cvj9LHpHCN X4ZdXlm22lHsMpiDqh/erobz+WwhOpDYc9S73FNsqEN42bqOm6CTvjpQtm0GdNEb k5l9YHlQL5n3NcnSOnECgYBce4uLh2pkog2g89eDa2nnvZ0gTk2zYhKA0wbzicK6 HtK5bAxf14BIgbyokYQrRb9eECaAW6gWwnshJLAV678ej8dbXaljOrZwteMqDM/z hLy9uk0yTBkeFfshTv61aC/mte6dURmZlElNrEI6hcPvv4HKTG4s2j2KOPS2ETjG iQKBgQCxa8NwzUkQnh+rI0Lq85BMhNJOQl0anZG1yXbpko0qb0T14h9unJXPtcj+ FuGfEBrXOd/vSb8wn9A9Whu9v0g6BoIVJX2XKOQLIC8pSWjf66x1K6h33S2lwTTf CHSRbiIIW2mhdVVXgQZGDAYJuDRSrbbQG9YnZx3AyZ3taRGbqA== -----END RSA PRIVATE KEY-----
2、生成pem文件
openssl req -new -x509 -days 3650 -key cert.key -out cert.pem
pem 文件内容
-----BEGIN CERTIFICATE----- MIID8zCCAtugAwIBAgIJAMSYcH7adC82MA0GCSqGSIb3DQEBCwUAMIGPMQswCQYD VQQGEwJ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UJ0C8NeQOEL0Aj1WMx3z/c8aguv+JRczMQIqZBoAdjARtEHdVntMRUivvgKuTp 4yxOO2/9k23QTm0/d1JzMK14/PAsKA2Snux69XLFW2Kfh/6T0e7IEXEEM3LROV5p SDT+AqyP8q4mb+JswA9Lzr+VLUMxH/Hl9tDtJHfWJ/6u3/6FwhkCColyA11QkSXe /WAoCDXMeg== -----END CERTIFICATE-----
两个文件生成完成,接下来就可以配置Nginx,然后就可以通过https访问我们的站点。
步骤:
1、将生成的key、pem文件拷贝到nginx的conf目录下,为了管理多个SSL证书,可以在nginx的 conf目录下建立cert目录专门存放SSL证书相关文件。
例如:在该目录下有两个SSL证书文件,
2、配置nginxSSL文件
将SSL相关的开启,ssl_certificate处 写我们生成的pem文件,ssl_certificate_key写我们生成的key文件。配置完成后检查nginx的配置文件 然后重启nginx.
server { listen 443 ssl; server_name 10.57.31.204 server.bondback.com; ssl_certificate cert/cert.pem ; ssl_certificate_key cert/cert.key; #ssl_certificate cert/bond.pem ; #ssl_certificate_key cert/bond.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { proxy_pass http://www; } }
通过IP或者绑定hosts访问https://10.57.31.204/
3、http转https配置
随着https使用越来越广泛,大多数网站已经使用https,而部分用户的使用习惯还是http,这时我们就可以配置http跳转https这种方式引导用户,同时提高网站的兼容性。
我们可以在http配置的location 一下配置
rewrite ^(.*)$ https://$host$1 permanent; listen 80; server_name server.bundbank.com; #charset koi8-r; #access_log logs/host.access.log main; location / { rewrite ^(.*)$ https://$host$1 permanent; # permanent 永久跳转 }
当我们访问http://10.57.31.204就会跳转到https://10.57.31.204
这样我们就可以完成nginx的ssl的配置,优化部分后期完善!
标签:rgb bar oiv gad vhd tms pyc bash man
原文地址:http://blog.51cto.com/dreamlinux/2153845