sae nodejs mysql_通过新浪云部署Node.js微信小程序商城(不用买域名、不用备案、不用配置https)...

本文档为微信小程序商城NideShop项目的安装部署教程(GitHub),欢迎star

一、购买新浪云SAE

为什么选择SAE?免费二级域名和支持https访问,不用备案,可用做微信小程序服务器。

选择对应的部署环境

自定义 -> 开发言语:自定义 -> 运行环境:云容器 -> 语言版本:自定义 -> 部署方式:手工部署 -> 环境配置:选择第一项(测试选最低配置即可) -> 实例个数:1(测试用选择1个即可) -> 二级域名:填写你的域名(这里为:tumobi.applinzi.com) -> 应用名称:填写你的名称(tumobi)

文中出现tumobi.applinzi.com的地方,请替换为你配置的二级域名

c074200c90d77894838bce030b62f743.png

选择部署环境

二、通过SSH连接云容器

三、安装配置nginx

apt update -y

apt upgrade -y

apt install nginx curl vim -y

service nginx start

curl localhost

解决方法:更改nginx默认监听的端口80为5050,并重新启动nginx

vim /etc/nginx/sites-available/default

nginx -t

service nginx restart

038a5442b6a25fcd00c77603becc2179.png

此处输入图片的描述

四、通过nvm安装node.js

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash

nvm安装成功后,关闭当前终端,重新连接

查看最新版本的Node.js并安装

nvm ls-remote

NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node nvm install v8.1.4

node -v

五、配置共享型MySQL并导入数据

创建MySQL成功后,选择管理操作,进入到phpmyadmin页面,选项导入

选择nideshop项目根目录下的nideshop.sql文件

六、本地部署NideShop

下载NideShop的源码

apt install git -y

cd /var/www

git clone https://github.com/tumobi/nideshop

安装ThinkJS

npm install thinkjs@2 -g --registry=https://registry.npm.taobao.org --verbose

thinkjs --version

安装依赖

cd /var/www/nideshop

npm install --registry=https://registry.npm.taobao.org --verbose

配置mysql

vim src/common/config/db.js

修改后:

6d084d2c75aa53bc565e527ddd8d2687.png

QQ截图20170715125320.png

启动:

npm start

curl localhost:8360

七 通过nginx、pm2进行线上部署

编译项目

npm runcompile

修改nginx配置

/etc/nginx/sites-available/default修改后

server {

listen 5050 default_server;

server_name tumobi.applinzi.com; #注意:修改成你的域名

root /var/www/nideshop;

set $node_port 8360;

index index.js index.html index.htm;

if ( -f $request_filename/index.html ){

rewrite (.*) $1/index.html break;

}

if ( !-f $request_filename ){

rewrite (.*) /index.js;

}

location = /index.js {

proxy_http_version 1.1;

proxy_set_header Connection "";

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header Host $http_host;

proxy_set_header X-NginX-Proxy true;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection "upgrade";

proxy_pass http://127.0.0.1:$node_port$request_uri;

proxy_redirect off;

}

location = /production.js {

deny all;

}

location = /testing.js {

deny all;

}

location ~ /static/ {

etag on;

expires max;

}

}

测试通过nginx访问

启动服务

node www/production.js

安装配置pm2

npm install -g pm2

修改项目根目录下的pm2.json为:

{

"apps": [{

"name": "nideshop",

"script": "www/production.js",

"cwd": "/var/www/nideshop",

"exec_mode": "cluster",

"instances": 1,

"max_memory_restart": "256M",

"autorestart": true,

"node_args": [],

"args": [],

"env": {

}

}]

}

启动pm2

pm2 startOrReload pm2.json

八 修改NideShop微信小程序的配置

微信小程序商城GitHub: https://github.com/tumobi/nideshop-mini-program

打开文件config/api.js,修改NewApiRootUrl为自己的域名,注册是https和后面的api/不能少

var NewApiRootUrl = 'https://tumobi.applinzi.com/api/';

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值