小程式部署全流程

不爱学习的摆烂王發表於2024-03-27

預設已擁有域名,且完成相關備案

本期從騰訊雲申請SSL證書開始

1、登入騰訊雲,搜尋SSL,免費申請,如下:

2、假定,已完成ssl證書申請

將申請來的SSL證書,配置到nginx,我這裡使用的伺服器是 Windows Server,

#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_names_hash_bucket_size 128;
    
    server {
        listen       7443 ssl;
        server_name  替換成自己的域名;
#日誌列印地址
        access_log D:/logs/nginx/access.log;
        error_log D:/logs/nginx/error.log;
        #證書存放地址,我這裡ssl資料夾與nginx.conf在同級
        ssl_certificate      ssl/digital-xxx.com_bundle.crt;
        ssl_certificate_key  ssl/digital-xxx.com.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;
            try_files $uri $uri/ /index.html;
        }

        location ^~/jeecg-boot/mes/ {
              proxy_pass  http://192.168.9.xx:8080/jeecg-boot/;
        }
        location ^~/jeecg-boot/tpm/ {
              proxy_pass  http://192.168.9.xx:8085/jeecg-boot/;
        }
        location ^~/jeecg-boot/ {
              proxy_pass  http://192.168.9.xx:8080/jeecg-boot/;
        }
        
        client_max_body_size 20m; # 客戶端上傳檔案大小限制
        client_body_buffer_size 512k;
        client_header_buffer_size 2k;
        
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        
    }
    
    server {
         listen       3000;
        server_name  替換成自己的域名;

        access_log D:/logs/nginx/access.log; 
        error_log D:/logs/nginx/error.log;
        
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }

       location ^~/jeecg-boot/mes/ {
              proxy_pass  http://192.168.9.xx:8080/jeecg-boot/;
        }
       location ^~/jeecg-boot/tpm/ {
              proxy_pass  http://192.168.9.xx:8085/jeecg-boot/;
        }
       location ^~/jeecg-boot/ {
              proxy_pass  http://192.168.9.xx:8080/jeecg-boot/;
        }

        client_max_body_size 20m; # 客戶端上傳檔案大小限制
        client_body_buffer_size 512k;
        client_header_buffer_size 2k;

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

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

}

這樣配置好之後,我們的域名就變成https安全的了,在這裡有幾點需要注意的是,ssl證書的存放位置是否指向正確,443埠是否開放

3、當我們配置好域名之後,就來準備小程式的一些配置

  將小程式連線後端的地址改為剛剛修改好的域名,值得一提的是,我這裡使用的nginx代理到後臺

  開啟微信開發工具(記得選擇程式碼壓縮),如下進行質量掃描,並不是全部透過才可以上傳,所以我們有時候不要鑽牛角尖,因為有些我是真的透過不了,懵懵的

  然後點選左上角的上傳按鈕就可以上傳啦,如果沒有上傳按鈕的話,那說明自己appid不對應,自己去微信公眾平臺檢視,然後到專案裡修改

4、上傳完之後,登入微信公眾平臺,點選版本管理,就可以在體驗版本看到了

5、點選左側開發管理,找到伺服器域名,將自己準備好的域名編輯上,我這裡埠是7443,是因為我的預設埠被佔用了,有一換成了別的埠,這裡配置完域名之後需要等待10-20分鐘左右,聽說是因為稽核或校驗或快取的緣故,反正等一下就行了

6、回到我們的版本管理,用手機測測體驗版的是否可以登入,如果可以的話就準備進行提交稽核,然後釋出吧

7、我出現的問題:

  7.1、手機流量登入不進去,連無線網(公司的網路是電信,工廠的專線也是電信,我換過別人的熱點,發現也不可登入)就可以登入,原因是這個域名的443埠被佔用的,所以我最後切換成了7443埠

相關文章