赞
踩
本例服务端使用的是php,搭建lnmp环境和配置https请查看我的上一篇文章,ubuntu 18.04.5 LTS 安装lnmp
1.下载php版本的腾讯官方小程序demo,wafer2-quickstart-php,解压之后的目录结构,
其中server目录是要部署到自己申请的腾讯云服务器上的,打开server目录,做如下配置,
登录自己的小程序,在开发设置里面查看appId和appSecret,
useQcloudLogin请设置为false,
2.登录自己的服务器,创建存储小程序数据的MySQL库,库名为cAuth,表结构请参考文件cAuth.sql,DB用户名和密码请自行设置,
创建结果,
将server目录打包成server.zip,上传到服务器web目录,我的目录是/var/www/html,解压,然后将目录名修改为weapp(起一个有意义的名字即可)
配置SDK文件,
这个路径可以自己定,我的路径是/etc/qcloud/sdk.config,内容根据指引设定,
下面是我的设置,仅供参考,
修改nginx配置,使小程序demo服务端weapp能够被正常访问,找到nginx配置文件,
下面是我的配置,仅供参考,
nginx配置
## # You should look at the following URL's in order to grasp a solid understanding # of Nginx configuration files in order to fully unleash the power of Nginx. # https://www.nginx.com/resources/wiki/start/ # https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/ # https://wiki.debian.org/Nginx/DirectoryStructure # # In most cases, administrators will remove this file from sites-enabled/ and # leave it as reference inside of sites-available where it will continue to be # updated by the nginx packaging team. # # This file will automatically load configuration files provided by other # applications, such as Drupal or Wordpress. These applications will be made # available underneath a path with that package name, such as /drupal8. # # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. ## # Default server configuration # server { listen 80 default_server; listen [::]:80 default_server; # SSL configuration # # listen 443 ssl default_server; # listen [::]:443 ssl default_server; # # Note: You should disable gzip for SSL traffic. # See: https://bugs.debian.org/773332 # # Read up on ssl_ciphers to ensure a secure configuration. # See: https://bugs.debian.org/765782 # # Self signed certs generated by the ssl-cert package # Don't use them in a production server! # # include snippets/snakeoil.conf; root /var/www/html; # Add index.php to the list if you are using PHP index index.html index.php index.htm index.nginx-debian.html; server_name www.lgcxc.cn; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } # pass PHP scripts to FastCGI server # location ~ \.php$ { include snippets/fastcgi-php.conf; # # # With php-fpm (or other unix sockets): fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; # # With php-cgi (or other tcp sockets): # fastcgi_pass 127.0.0.1:9000; # } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } } # Virtual Host configuration for example.com # # You can move that to a different file under sites-available/ and symlink that # to sites-enabled/ to enable it. # #server { # listen 80; # listen [::]:80; # # server_name example.com; # # root /var/www/example.com; # index index.html; # # location / { # try_files $uri $uri/ =404; # } #} server { listen 443 ssl; server_name www.lgcxc.cn; ssl_certificate /etc/nginx/www.lgcxc.cn/Nginx/1_www.lgcxc.cn_bundle.crt; ssl_certificate_key /etc/nginx/www.lgcxc.cn/Nginx/2_www.lgcxc.cn.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; location /weapp/ { rewrite ^/weapp/(.*)$ /$1 break; 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:8082; } } server { listen 8082; server_name 127.0.0.1; root /var/www/html/weapp; index index.html index.php; if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; } }
访问项目weapp,查看服务端部署是否正常,
测试登录服务,看看相应了什么,
这个错误码,表明我们服务端配置正确,接下来要使用客户端联调。
查看DB存储的登录用户信息,
至此,就可以愉快的开发你的小程序了。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。