2021.11.17 | 访客 | 2388次围观
微信小程序的后台接口,需要https,所以今天去试试https怎么搞,阿里有免费的1年的ssl证书申请,
yundun.console.aliyun.com/?spm=5176.2…
准备一个域名,比如拿了自己一个二级域名做测试,test.anool.net
点击创建域名
嗯,还需要验证,这个操作去域名运营商那,比如我的域名用的是花生壳
就是添加一条txt记录,反正升级一个txt功能又花了我36元,不知道是不是每年的?
最后申请证书审核,应该很快,这里我下载nginx的做测试
下载下来就是证书
放到nginx下的cert文件夹下,没有就新建一个文件夹
然后安装nginx
我这边准备了一台电脑测试,上面的8105端口项目需要https
最终理想是访问https:/test.anool.net 可以访问项目,https其实是访问443端口,不过443被运营商封了,改成了442,路由转发改一下,nginx配置改一下,配置在文章最后
最后只能 https:/test.anool.net:442 这样访问了,测试了一下,小程序,能添加这个地址
小伙伴们,告诉我一下,如果长期这样搞,会不会影响我的域名呀,反正我测试完就解除部署了
因为是提供给外包人员小程序开发的,还没有验证过,仅供参考!
nginx配置
#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;
server {
listen 8999;
server_name localhost;
location / {
proxy_pass http://192.168.0.18:8105;
}
}
server {
listen 442 ssl;
#配置HTTPS的默认访问端口为443。
#如果未在此处配置HTTPS的默认访问端口,可能会造成Nginx无法启动。
#如果您使用Nginx 1.15.0及以上版本,请使用listen 443 ssl代替listen 443和ssl on。
server_name test.anool.net; #需要将yourdomain.com替换成证书绑定的域名。
root html;
index index.html index.htm;
ssl_certificate cert/6182690_test.anool.net.pem; #需要将cert-file-name.pem替换成已上传的证书文件的名称。
ssl_certificate_key cert/6182690_test.anool.net.key; #需要将cert-file-name.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; #表示使用的TLS协议的类型。
ssl_prefer_server_ciphers on;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://192.168.0.18:8105;
}
#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 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.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;
# }
#}
}作者:龙哥leon
链接:https://juejin.cn/post/7002429259574673421
来源:稀土掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
版权声明
本文仅代表作者观点,不代表xx立场。
本文系作者授权xxx发表,未经许可,不得转载。


发表评论