目前小程序特别流行,但是我们要开发一个属于自己的小程序的时候必须拥有自己的域名并且配置https安全请求备案到小程序管理员处。记录一下nginx配置ssl证书,省的我们自己的服务配置SSL。
一、买一个云服务器(我用的腾讯云),域名(需要备案,麻烦的一批),证书(免费的)
总会有疯狂打折的云,多瞅瞅再买;
域名不需要太正式 .abc .xyz 的也就1块钱,便宜;
证书就免费啦。。。。
证书下载下来是这样的:
二、下载安装配置nginx
此处不再赘述,操作再集成fastdfs的日志中已经写啦。https://blog.csdn.net/u011909918/article/details/88528931
备份一下以前的nginx配置文件(/usr/local/nginx/conf/nginx.conf),然后修改配置文件:
http转https:
代码如下:
#############https配置###########################
server {
listen 443;
server_name 域名;
ssl on;
ssl_certificate 证书文件(可以用绝对路径,也可以用相对路径,我是在同文件夹下,下同);
ssl_certificate_key 证书key文件;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
####默认#####
location / {
root html;
index index.html index.htm;
}
###配置fastdfs#####
location /group1/M00 {
root /opt/fastdfs/storage/data;
ngx_fastdfs_module;
}
###配置服务###
location /skill {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:9999/;
}
}
#############http配置###########################
server {
listen 80;
server_name 域名;
rewrite ^(.*)$ https://$host$1 permanent;
}
三、重启nginx
#######查看配置文件是否可用#######
/usr/local/nginx/sbin/nginx -t
#成功结果:
#ngx_http_fastdfs_set pid=26436
#nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
#nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
##########重启nginx#############
/usr/local/nginx/sbin/nginx -s reload
四、问题解决
问题:nginx: [emerg] unknown directive "ssl"
解决办法:
1、打开nginx解压路径,使用命令以下命令添加组件和支持。
####先安装openssl
yum -y install openssl openssl-devel
###只添加ssl支持
./configure --with-http_ssl_module
###添加fastdfs模块和ssl支持
./configure --prefix=/usr/local/nginx --add-module=/opt/download/fastdfs-nginx-module/src/ --with-http_ssl_module
2、然后使用make命令编译,千万不用使用make install安装。
3、拷贝nginx命令文件到安装目录下
####在这之前最好备份一下旧的启动文件
cp /opt/download/nginx-1.10.1/objs/nginx /usr/local/nginx/sbin/nginx
五、OK,大功告成。