1、
sudo apt-get install openssl libssl-dev
# ./configure --with-http_stub_status_module --with-http_ssl_module
# make && make install
nginx快速退出
../sbin/nginx -s quit
2、
生成证书 # 1、首先,进入你想创建证书和私钥的目录,例如: cd /etc/nginx/ # 2、创建服务器私钥,命令会让你输入一个口令: openssl genrsa -des3 -out server.key 1024 # 3、创建签名请求的证书(CSR): openssl req -new -key server.key -out server.csr # 4、在加载SSL支持的Nginx并使用上述私钥时除去必须的口令: cp server.key server.key.org openssl rsa -in server.key.org -out server.key # 5、最后标记证书使用上述私钥和CSR: openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
3、配置
server{
listen 80;
rewrite ^(.*)$ https://$host$1 permanent;
}
server {
listen 443;
server_name localhost;
ssl on;
ssl_certificate /usr/local/nginx/ssl/server.crt;
ssl_certificate_key /usr/local/nginx/ssl/server.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
省略
}