最近有个项目须要在nginx上配置ssl具体实施部署方法以下:html
建立nginx证书配置目录nginx
#mkdir -p /usr/local/nginx/conf/ssl
进入nginx配置文件目录/usr/local/nginx/ssl服务器
#cd /usr/local/nginx/conf/ssl
在服务器上生成私钥session
#openssl genrsa -out server.key 2048
生成csr文件ide
#openssl req -new -key server.key -out server.csr You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]: State or Province Name (full name) []: Locality Name (eg, city) [Default City]: Organization Name (eg, company) [Default Company Ltd]: Organizational Unit Name (eg, section) []: Common Name (eg, your name or your server's hostname) []: 本身须要ssl的域名 Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []:
生成好csr文件后须要把这个文件提交给证书供应商让他们颁发证书。ui
证书颁发好以后须要把证书文件(server.cer)、server.key、server.csr这三个文件放到nginx ssl配置目录中spa
“/usr/local/nginx/conf/ssl“.net
在nginx.conf里配置sslcode
server {
listen 443;
server_name www.xxx.com;
ssl on;
ssl_certificate /usr/local/nginx/conf/server.cer;
ssl_certificate_key /usr/local/nginx/conf/server.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;orm
location / { root html; index index.html index.htm; }
}
重启nginx