首頁 >運維 >CentOS >關於CentOS YAPI部署(程式碼分享)

關於CentOS YAPI部署(程式碼分享)

奋力向前
奋力向前轉載
2021-09-13 11:26:491673瀏覽

之前的文章《解決uni-app入坑集合的一個方案(分享)》中,跟大家介紹了怎麼解決uni-app入坑集合。以下這篇文章跟大家介紹CentOS YAPI部署,夥伴們來看看。

關於CentOS YAPI部署(程式碼分享)

YAPI部署(centos)

#環境

Node mongodb

git 

yum install git.

node

#
yum install nodejs

pm2

npm i -g pm2

mongodb安裝配置設定

url : https://www.mongodb.com/try/download/community

# 下载
wget https://repo.mongodb.org/yum/redhat/8/mongodb-org/5.0/x86_64/RPMS/mongodb-org-server-5.0.0-1.el8.x86_64.rpm
# 安装
rpm -i mongodb-org-server-5.0.0-1.el8.x86_64.rpm
# 启动服务
systemctl start mongod.service

## 无法启动 给权限
chown -R mongod:mongod /var/lib/mongo
chown -R mongod:mongod /var/log/mongodb
chown mongod:mongod /tmp/*.sock	

yapi安裝配置

wget https://github.com/YMFE/yapi/archive/refs/tags/v1.9.3.tar.gz

tar -zxvf v1.9.3.tar.gz
mv yapi-1.9.3 yapi
cd yapi

cp config_example.json  config.json

把預設的資料庫連結配置乾掉

vi config.json

db:{
  - user:'test',
  - pass:'test'
}

初始化

# 初始化 依赖
npm install --production --registry https://registry.npm.taobao.org
# 初始化数据库
npm run install-server

# 启动
node server/app.js   
#or
pm2 start server/app.js --name yapi

禁止註冊

{
  "port": "*****",
  "closeRegister":true
}

##外網部署之後1.9.2以下版本有上傳提權漏洞,應該要幹掉註冊

######nginx安裝設定######
yum install nginx
vi /etc/nginx/conf.d/yapi.conf
######綁定網域做轉寄######
server{
  server_name xxxx.com;
  #cache
  location ~* \.(?:jpg|jpeg|png|gif|ico|css|js)$ {
    proxy_pass http://127.0.0.1:3000;
    proxy_redirect  off; 	
    proxy_set_header Host  $host;

    expires 365d;
    add_header Cache-Control "public"; 
  }
  location / {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_pass http://127.0.0.1:3000;
    proxy_redirect  off;
    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_send_timeout      300;
    proxy_read_timeout      300;

    add_header Last-Modified $date_gmt;
    add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
    if_modified_since off;
    expires off;
    etag off;
  }

  #https
  #listen 443 ssl;
  #ssl_certificate	/etc/nginx/cer/fullchain.crt;
  #ssl_certificate_key /etc/nginx/cer/private.pem;
  #ssl_protocols TLSv1.1 TLSv1.2;
  #ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
  #ssl_prefer_server_ciphers on;
  #ssl_session_cache shared:SSL:10m;
  #ssl_session_timeout 10m;
}

#server{
#  if ($host = xxxx.com) {
#      return 301 https://$host$request_uri;
#  } 
#
#  server_name xxxx.com;
#  listen 80;
#  return 404;
#
###完成! ######推薦學習:###CentOS入門教學#######

以上是關於CentOS YAPI部署(程式碼分享)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:chuchur.com。如有侵權,請聯絡admin@php.cn刪除