最近有個項目須要在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