微信小程序开发之https

微信小程序开发要求

注意:申请SSL证书使用微信小程序开发接入域名(微信服务器配置信息)。配置好的SSL证书去ATS检测确定符合小程序要求
微信小程序开发之https_第1张图片
微信小程序开发要求,需要域名满足https
微信小程序开发之https_第2张图片
在腾讯云或者华为云等云服务器下载ssl证书,这里使用nginx

nginx安装部署

1.上传nginx安装包至/tmp目录
微信小程序开发之https_第3张图片
下载nginx需要的依赖,先下载到服务器或虚拟机内

yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

2.解压nginx安装包至指定目录

cd /tmp

tar -zxvf nginx-1.16.1.tar.gz -C /usr/local

cd /usr/local

mkdir nginx

cd /usr/local/nginx-1.16.1

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

make install
微信小程序开发之https_第4张图片
说明:

nginx-1.16.1主要为源码安装

nginx为我们的主要使用,后面的配置都会在此文件夹中进行
微信小程序开发之https_第5张图片

nginx配置https

cd /usr/local/nginx/conf/

mkdir ssl

将域名证书上传至ssl文件夹下面,无论腾讯云还是华为云,只要你的域名备案完毕,都可以下载证书,我主要采用nginx需要的域名证书
配置文件如下,仅供参考

cd /usr/local/nginx/conf
vim nginx.conf

user root;
worker_processes auto;

#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  650;

client_max_body_size 500M;

gzip on;
gzip_min_length  50k;
gzip_buffers     64 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types   application/json text/plain application/javascript application/x-javascript text/css application/xml;
gzip_vary on;

# 小程序
upstream xcx {
server 121.22.91.99:8080;
}

# tomcat教培后台
upstream tomcat {
server 121.22.91.99:7070;
}



#配置nginx前台访问
server {
    listen        80;#nginx前台访问地址
    server_name  121.37.95.90;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;
  
    #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;
    }
    

}

#配置ssl
server {
listen 443 ssl;
server_name jpg.com;
ssl_certificate /usr/local/nginx/conf/ssl/jpg.com_server.crt;
ssl_certificate_key /usr/local/nginx/conf/ssl/jpg.com_server.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;

    # tomcat
    location /tomcat{
        proxy_pass http://121.22.91.99:7070;
        #proxy_set_header Host $HOST;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        client_max_body_size 1000m;
        fastcgi_read_timeout 150;
    }

    # xcx 后端
    location /znpg{
        proxy_pass http://121.22.91.99:8080;
       # proxy_set_header Host $host:$server_port;
        proxy_set_header Host $HOST;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        client_max_body_size 500m;
        fastcgi_read_timeout 150;
    }

    

}

}
2.nginx启停命令
启动命令
cd /usr/local/nginx/conf
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
停止命令
lsof -i:80
kill -9 pid

tomcat启动前端服务

1.安装jdk
cd /usr/local
mkdir java
chmod -R 777 java
cd /tmp
tar -zxvf jdk-11.0.8_linux-x64_bin.tar.gz -C /usr/local/java
记录java的解压目录,配置环境变量时要用
/usr/local/java/jdk-11.0.8

vim /etc/profile
export JAVA_HOME=/usr/local/java/jdk-11.0.8
export JRE_HOME= J A V A H O M E / j r e e x p o r t C L A S S P A T H = . : {JAVA_HOME}/jre export CLASSPATH=.: JAVAHOME/jreexportCLASSPATH=.:{JAVA_HOME}/lib: J R E H O M E / l i b e x p o r t P A T H = {JRE_HOME}/lib export PATH= JREHOME/libexportPATH={JAVA_HOME}/bin:$PATH
source /etc/profile
2.安装tomcat
tar -zxvf apache-tomcat-9.0.37.tar.gz -C /usr/local
cd /usr/local
mv /usr/local/apache-tomcat-9.0.37 /usr/local/tomcat_7070
cd /usr/local/tomcat_7070/conf
vim server.xml
微信小程序开发之https_第6张图片
3.启动tomcat
cd /usr/local/tomcat_7070/bin
./startup.sh
cd …/logs
tail -f catalina.out

浏览器访问:
http://jpg.com:7070/jpg/index.html#/index(假的地址,仅为说明)

jar包部署后端服务

nohup java -jar aa.jar

防火墙及安全组开放端口

firewall-cmd --zone=public --add-port=7070/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-all

你可能感兴趣的:(前端,微信小程序,https,小程序)