1.申请免费ssl证书,具体方法百度即可
2.下载免费证书,并把证书拷贝至服务器nginx目录下
3.配置服务文件
4.添加443安全组
附简单代码:
在nginx.conf监听443端口和80端口
server {
listen 443;
server_name walnutui.com; # 你的域名
ssl on;
root /home/talk/www/; # 前台文件存放文件夹,可改成别的
index index.html index.htm;# 上面配置的文件夹里面的index.html
ssl_certificate cert/1757867_www.walnutui.com.pem;# 改成你的证书的名字
ssl_certificate_key cert/1757867_www.walnutui.com.key;# 你的证书的名字
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
index index.html index.htm;
}
}
server
{
listen 80;#监听端口
server_name walnutui.com;#域名
index index.html index.htm index.php;
root /home/talk/www/;#站点目录
rewrite ^(.*)$ https://$host$1 permanent; # 把http的域名请求转成https
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
{
expires 30d;
# access_log off;
}
location ~ .*\.(js|css)?$
{
expires 15d;
# access_log off;
}
access_log off;
}
OK 锁已经挂上了