老司机三级_天天干天天操天天爽_女人被爽到娇喘呻吟视频_久久国产精品99久久久大便 - 亚洲日本系列

CentOS7.3下部署基于Node.js的微信小程序商城

  • • 發(fā)表于 8年前
  • • 作者 微信小程序商城開(kāi)發(fā)
  • • 2830 人瀏覽
  • • 0 條評(píng)論
  • • 最后編輯時(shí)間 8年前
  • • 來(lái)自 [技 術(shù)]

原創(chuàng)聲明:本文為作者原創(chuàng),未經(jīng)允許不得轉(zhuǎn)載,經(jīng)授權(quán)轉(zhuǎn)載需注明作者和出處

本文檔為微信小程序商城NideShop項(xiàng)目的安裝部署教程,歡迎star

環(huán)境介紹

阿里云 ECS CentOS 7.3 64 云服務(wù)器ECS優(yōu)惠券領(lǐng)取鏈接

更新系統(tǒng)和安裝 git、vim、curl

yum update -y
yum install curl git -y

通過(guò) nvm 安裝 Node.js

  • 安裝 nvm

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

    驗(yàn)證安裝是否成功

    source ~/.bashrc
    nvm --version
    

    看到輸出版本信息 0.33.5 表示安裝成功

  • 查看最新 8.x 版本 Node.js 版本并安裝

    nvm ls-remote
    nvm install v8.2.1
    node -v
    

    看到輸出版本信息 v8.2.1 表示安裝成功

    必須安裝 Node.js 8.x 以上版本

安裝 MySQL 5.7

yum install https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm -y
yum install mysql-community-server -y

啟動(dòng) mysql

systemctl start mysqld
systemctl enable mysqld

查找 root 的初始密碼

cat /var/log/mysqld.log | grep password

更改密碼

mysql_secure_installation

回車(chē)后輸入查找到的密碼,然后按照料提示更改密碼
注意新密碼必須包含特殊字符、數(shù)字、和大小寫(xiě)字母且不得少于8位,否則更改失敗。

驗(yàn)證 mysql 是否安裝成功

mysql -uroot -p

回車(chē)后輸入查找到的密碼,登錄成功后的樣子

image.png

開(kāi)始運(yùn)行 NideShop

  • 下載 NideShop 的源碼
    mkdir /var/www
    cd /var/www
    git clone https://github.com/tumobi/nideshop
    
  • 全局安裝 ThinkJS 命令

    npm install -g think-cli
    thinkjs -v
    
  • 安裝依賴

    cd /var/www/nideshop
    npm install
    
  • 創(chuàng)建數(shù)據(jù)庫(kù)并導(dǎo)入數(shù)據(jù)

    mysql -uroot -p -e "create database nideshop character set utf8mb4"
    mysql -uroot -p nideshop < /var/www/nideshop/nideshop.sql
    
  • 修改 Nideshop 的數(shù)據(jù)庫(kù)配置

    vim src/common/config/adapter.js
    

    修改后
    ```
    24 /*
    25
    model adapter config
    26 @type {Object}
    27
    /
    28 exports.model = {
    29 type: ‘mysql’,
    30 common: {
    31 logConnect: isDev,
    32 logSql: isDev,
    33 logger: msg => think.logger.info(msg)
    34 },
    35 mysql: {
    36 handle: mysql,
    37 database: ‘nideshop’,
    38 prefix: ‘nideshop_’,
    39 encoding: ‘utf8mb4’,
    40 host: ‘127.0.0.1’,
    41 port: ‘3306’,
    42 user: ‘root’,
    43 password: ‘你的密碼’,
    44 dateStrings: true
    45 }
    46 };

>注意 encoding,prefix 的值

編譯項(xiàng)目

npm run compile

以生產(chǎn)模式啟動(dòng)

node production.js

打開(kāi)另一個(gè)終端驗(yàn)證是否啟動(dòng)成功

curl -I http://127.0.0.1:8360/

輸出 HTTP/1.1 200 OK,則表示成功
** Ctrl + C 停止運(yùn)行**
> 為防止后面操作出現(xiàn)[Error] Error: Address already in use, port:8360. 的錯(cuò)誤,一定要記得Ctrl + C停止運(yùn)行,并確保curl -I http://127.0.0.1:8360/不能訪問(wèn)

### 使用 PM2 管理服務(wù)

+ 安裝配置 pm2

npm install -g pm2

修改項(xiàng)目根目錄下的 pm2.json 為:

vim pm2.json

修改后的內(nèi)容如下 :

{
“apps”: [{
“name”: “nideshop”,
“script”: “production.js”,
“cwd”: “/var/www/nideshop”,
“exec_mode”: “fork”,
“max_memory_restart”: “256M”,
“autorestart”: true,
“node_args”: [],
“args”: [],
“env”: {

}

}]
}

如果服務(wù)器配置較高,可適當(dāng)調(diào)整 max_memory_restart 和instances的值
+ 啟動(dòng)pm2

pm2 start pm2.json

成功啟動(dòng)

![image.png](http://upload-images.jianshu.io/upload_images/3985656-21a6aa802f7bb1ed.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

再次驗(yàn)證是否可以訪問(wèn)

curl -I http://127.0.0.1:8360/


### 使用 nginx 做反向代理

yum install nginx -y
systemctl start nginx.service
systemctl enable nginx.service

測(cè)試本地是否可以正常訪問(wèn)

curl -I localhost

修改nginx配置

cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
vim /etc/nginx/nginx.conf

內(nèi)容如下(只需更改 server 里面的內(nèi)容)

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

Load dynamic modules. See /usr/share/nginx/README.dynamic.

include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024;
}

http {
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  /var/log/nginx/access.log  main;

sendfile            on;
tcp_nopush          on;
tcp_nodelay         on;
keepalive_timeout   65;
types_hash_max_size 2048;

include             /etc/nginx/mime.types;
default_type        application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

server {
    listen 80;
    server_name nideshop.com www.nideshop.com; # 改成你自己的域名
    root /var/www/nideshop/www;
    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 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 ~ /static/ {
        etag         on;
        expires      max;
    }
}

}

+ 重新啟動(dòng)nginx并驗(yàn)證nginx是否還可以正常訪問(wèn)

nginx -t
systemctl restart nginx.service
curl http://127.0.0.1/

如果返回的是下圖的json數(shù)據(jù)則表示nginx反向代理配置成功

![nginx轉(zhuǎn)發(fā)成功](http://upload-images.jianshu.io/upload_images/3985656-ff191d58e075c41c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
> 注:阿里云默認(rèn)外網(wǎng)不能訪問(wèn)80/443端口,請(qǐng)更改實(shí)例的安全組配置,配置教程:https://help.aliyun.com/document_detail/25475.html?spm=5176.doc25475.3.3.ZAx4Uo

### 配置https訪問(wèn)
+ 安裝certbot

yum install epel-release -y
yum install certbot-nginx -y
certbot —nginx

如果 certbot -nginx 這步出錯(cuò),則執(zhí)行

pip install —upgrade —force-reinstall ‘requests==2.6.0’ urllib3

重新執(zhí)行 certbot --nginx

+ 配置自動(dòng)更新證書(shū)

certbot renew —dry-run

> 詳情文檔請(qǐng)查看:https://certbot.eff.org/#ubuntuxenial-nginx

+ 測(cè)試瀏覽器使用https形式訪問(wèn)是否成功
![配置https訪問(wèn)成功](http://upload-images.jianshu.io/upload_images/3985656-9b0cfb1db7c99c3e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)


### 修改NideShop微信小程序客戶端的配置
微信小程序商城客戶端GitHub: https://github.com/tumobi/nideshop-mini-program
打開(kāi)文件config/api.js,修改NewApiRootUrl為自己的域名

var NewApiRootUrl = ‘https://www.nideshop.com/api/‘;
```

注意https和后面的api/不能少

到此部署成功。如有問(wèn)題請(qǐng)加QQ群:497145766

分享到:
0條評(píng)論
Ctrl+Enter
作者

微信小程序商城開(kāi)發(fā)

微信小程序商城開(kāi)發(fā)

APP:0 帖子:5 回復(fù):11 積分:94

已加入社區(qū)[2971]天

主人太懶,簽名沒(méi)設(shè)置!

作者詳情》
Top