首先去买个域名,阿里云
等,随便买一个才7 ~15元,有了域名我们就可以去申请免费的证书了我是用的FreeSSL网址在这里https://freessl.cn/apply
!现在我们去FreeSSL申请证书
写完邮箱可能会让你验证 验证一下就好了 然后点击创建
上图提示了私钥已经创建完成,我们下载保存就好(其实也用不到啦,请往下看)。
上图就是私钥的内容了,我们复制上图中记录值
的内容,然后去花生壳创建域名解析(就是我们买的域名 绑定上自己的IP IP地址一定要是公网上的哦
)
上图是我配置好的解析
上图就是需要配置两个内容,IP映射
andTXT映射
配置完成后,我们需要去服务器Linux Centos 7.x
里搞一下,请往下看
首先进入httpd的目录
[root@cdh03 Rone]# cd /var/www/html/
建立文件夹
[root@cdh03 html]# mkdir .well-known/pki-validation/
创建文件
[root@cdh03 html]# vi.well-known/pki-validation/fileauth.txt
然后将我们复制的TXT记录值
粘贴进去
:wq!
退出保存。
这里我们需要确保你的服务器里开启了httpd服务,最简单的方法就是在浏览器里直接输入网址
10.232.12.23
出现如下界面则说明httpd是打开的
接着我们在确认一下,刚刚新建的文件是否能够读取到
输入这个路径(CDH03换成你的IP or 域名)
http://cdh03/.well-known/pki-validation/fileauth.txt
这里读取到了,说明配置成功,接下来我们做申请证书的最后一步
验证的结果:
TXT的和IP的都验证一下,省得证书申请失败
这里都通过了,则直接点击验证
经过1分钟左右就会有结果了
点击下载证书就OK了,下图是我下载好的证书
到这里则申请SSL证书完毕!!!
接下来就是配置ngnix反向代理https了,这里我只给出我配好的文件吧,不想多说了,我太难了~~~
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream myServer {
server ssss.xxx:8688;
}
# server {
# listen 8080;
# server_name www.ssss.xxx;
#ssl on;
#ssl_certificate /usr/local/nginx/conf/full_chain.pem;
#ssl_certificate_key /usr/local/nginx/conf/private.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;
#charset koi8-r;
#access_log logs/host.access.log main;
# location / {
#root htm;
# }
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# root html;
# }
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
#}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
server {
listen 8998 ssl;#我这里改了端口 默认为443
ssl on;
server_name www.ssss.xxx;
ssl_certificate /usr/local/nginx/conf/full_chain.pem;
ssl_certificate_key /usr/local/nginx/conf/private.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
#转发到的IP 以及端口
proxy_pass http://myServer;
proxy_redirect off;
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_set_header Cookie $http_cookie;
#proxy_cookie_path
chunked_transfer_encoding off;
}
}
}
眼睛疼!再见!!!!
-----------------------以下为更新内容-----------------------
现在百度云、阿里云、腾讯云都需要备案,上述申请证书的步骤要往后面推一下,
正确的步骤是
买服务器 --> 备案 --> 买域名 -->申请证书 --> 配置NGINX(https) -->开发小程序服务端
有问题请联系我