Penguin Cho
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- title: Strapi 部署及設定 tags: Strapi description: Strapi quick start! --- # 將Strapi 部署到網路上吧!(Strapi介紹-後篇) <!-- Put the link to this slide here so people can follow --> 來源: https://strapi.io/documentation/3.0.0-beta.x/guides/deployment.html [前篇(快速入門)](https://hackmd.io/oXdEw-gBTSGheNsARMJYVg) [中篇(概念架構介紹)](https://hackmd.io/LqgfRVBXQf-OYFrvdiT7Hw) [後篇(部署及設定)](https://hackmd.io/-2zeYcrgR52aI-gssI-XFQ) :+1: 將Strapi部署到雲端平台,隨時都可以管理你的後台資料,讓你的前端網頁輕鬆使用~ --- ## Step 1. 更改相關設定 - 更改server相關設定 將host以及port設為動態設定,能夠在啟動專案時透過更改環境變數的方式,設定其變數 路徑 - `./config/environments/production/server.json` ```json= { "host": "${process.env.APP_HOST || '127.0.0.1'}" "port": "${process.env.NODE_PORT || 1337}", } ``` --- <!-- --- --> ## Step 2. 使用AWS S3作為資料host 不使用上傳檔案的功能可以跳過此步驟 :::info AWS在註冊過後大約一天的時間,才能使用S3的功能 ::: 透過AWS > 服務 搜尋==S3==,進入到S3的頁面,會像是以下頁面(此為已建立儲存貯體的畫面) ![AWS S3頁面](https://i.imgur.com/obkfhh5.png) 接著開始新增一個儲存貯體吧! 從畫面中的按鈕 ==+建立儲存貯體== ### 1. 首先輸入名稱,選擇適合專案的區域 > 點擊下一頁 ### 2. 設定選項 基本上不用特別勾選,依照你的專案而定 > 點擊下一頁 ### 3. ==設定許可(重要!!)== 1. 將 **封鎖所有公開存取** 的核選方塊==取消勾選== 2. `不要勾選` **封鎖透過新的存取控制清單 (ACL) 授與的對儲存貯體和物件的公開存取權** 3. `不要勾選` **封鎖透過任何存取控制清單 (ACL) 授與的儲存貯體和物件的公開存取權** 4. ==勾選== **封鎖透過新的公開儲存貯體政策授與的對儲存貯體和物件的公開存取權** 5. ==勾選== **封鎖透過任何公開儲存貯體政策授與的對儲存貯體和物件的公開和跨帳戶存取權** > 點擊下一頁 ### 4. 檢閱,並點擊建立儲存貯體 儲存貯體已建立完成,接著需要在strapi中安裝aws s3的插件以及設定相關密鑰才能在strapi中使用AWS S3的服務,可以在完成後試著上傳一個檔案來測試AWS S3的功能 ### 5. 安裝AWS S3的provider插件 `npm install strapi-provider-upload-aws-s3@beta` 完成後在strapi admin,選擇擴充功能中的FILES UPLOAD的設定(齒輪) 在儲存空間的選單中,會多了Amazon Web Service S3的選項就表示成功了! 而我們等一下部署到heroku再來設定Token 如下圖 ![file upload](https://i.imgur.com/ZITd3Ly.png) ![upload](https://i.imgur.com/7qlAshN.png) --- ## Step 3. 部署到Heroku 僅介紹Heroku平台方式,原文中還有其他像是AWS, Degital Ocean...的方式 (Heroku使用的資料庫add-on為Postgres) - ### 安裝及登入Heroku #### 安裝: mac: `brew tap heroku/brew && brew install heroku` windows: 直接使用安裝檔 [64bit](https://cli-assets.heroku.com/heroku-x64.exe) / [32bit](https://cli-assets.heroku.com/heroku-x86.exe) ubuntu: `sudo snap install --classic heroku` #### 登入: `heroku login`來登入(或是使用heroku網站的登入也可以) - ### 新建Strapi專案 / 使用既有專案 新建專案: `strapi new my-project --quickstart` 新建專案如要使用AWS請依照AWS S3的步驟設定 - ### 修改 `.gitignore` 將`package-lock.json`這行 加入`.gitignore`以免出錯 ```json= package-lock.json ``` - ### git 上傳 路徑 - `./你的專案/` ```javascript= //CLI cd my-project //移動到專案目錄 git init //git 初始化 git add . //git 增加所有檔案 git commit -m "Initial Commit" //git 上傳並附上訊息"Initial Commit" ``` - ### 創建新的Heroku專案 路徑 - `./你的專案/` `heroku create` 或是自訂專案名稱 `heroku create custom-project[自訂專案名稱]` - ### 設定Heroku的資料庫(PostgresSQL addOn 為例) 路徑 - `./你的專案/` 在heroku專案新增postgresQL的插件 `heroku addons:create heroku-postgresql:hobby-dev` 取得資料庫相關設定 `heroku config` 會取得像是以下資料格式 `ostgres://ebitxebvixeeqd:dc59b16dedb3a1eef84d4999sb4baf@ec2-50-37-231-192.compute-2.amazonaws.com: 5432/d516fp1u21ph7b` 資料分別為 `postgres:// USERNAME : PASSWORD @ HOST : PORT : DATABASE_NAME` 將要依此做以下資料庫的設定,==相關參數請填入你在heroku config拿到的設定== ```javascript= //CLI heroku config:set DATABASE_USERNAME=ebitxebvixeeqd heroku config:set DATABASE_PASSWORD=dc59b16dedb3a1eef84d4999a0be041bd419c474cd4a0973efc7c9339afb4baf heroku config:set DATABASE_HOST=ec2-50-37-231-192.compute-2.amazonaws.com heroku config:set DATABASE_PORT=5432 heroku config:set DATABASE_NAME=d516fp1u21ph7b ``` - ### 更新 strapi資料庫檔案的設定 路徑 - `./你的專案/config/environments/production/database.json` ```json= { "defaultConnection": "default", "connections": { "default": { "connector": "strapi-hook-bookshelf", "settings": { "client": "postgres", "host": "${process.env.DATABASE_HOST}", "port": "${process.env.DATABASE_PORT}", "database": "${process.env.DATABASE_NAME}", "username": "${process.env.DATABASE_USERNAME}", "password": "${process.env.DATABASE_PASSWORD}", "ssl": true }, "options": {} } } } ``` - ### 安裝`pg`(postgres套件) 路徑 - `./你的專案/` `npm install pg --save` - ### 上傳剛剛更新的修改,完成!! ```javascript= //CLI git add . git commit -m "Update database config" git push heroku master //推到master分支並發布到heroku heroku open //開啟此專案的網站! ``` - ### 接著你就可以在已部署的網頁中取得API了 使用方法與localhost方法一樣,只是網址改為heroku專案的網址 如果403 forbidden,admin 頁面中的身份與權限,有相關API使用的設定,詳見[前篇(快速入門)](https://hackmd.io/oXdEw-gBTSGheNsARMJYVg?view#Step-5-%E8%A8%AD%E5%AE%9A-%E8%A7%92%E8%89%B2%E8%88%87%E6%AC%8A%E9%99%90) 如需無法使用graphQL,請安裝graphQL插件並修改其設定檔,詳見[前篇(快速入門)](https://hackmd.io/oXdEw-gBTSGheNsARMJYVg?view#Step-6-%E9%96%8B%E5%BF%83%E4%BD%BF%E7%94%A8API) --- - ### 補充設定AWS S3(可以跳過) - 在AWS右上角找你的帳號,並從選單中點擊==我的安全登入資料== - 在您的安全登入資料頁面中,點開存取金鑰,並點擊==建立新的存取金鑰== - 在跳窗中會有 ==存取金鑰ID(Access API Token)==以及==私密存取金鑰(Secret Access Token)==,這兩組金鑰將會用於FILES UPLOAD的設定(請詳記或是不要關掉AWS跳窗) - 接著在你已發佈的Heroku專案的Strapi admin網頁中,在左邊找到並點擊==擴充功能== - 在擴充功能中找到==FILES UPLOAD==並點擊齒輪來設定,在儲存空間的下拉選單選擇==Amazon Web Service S3== - 在==Access API Token==和==Secret Access Token==分別填入剛剛拿到的金鑰,==Region==選擇你在AWS S3中選擇的區域(預設是us-east-2),最後在==Bucket==填入你==儲存貯體==的名稱 - 完成並可以測試上傳! #### 測試上傳: - 點擊Heroku專案中的strapi admin左邊的檔案上傳,並上傳一個圖片 - 上傳成功後,在你AWS S3的頁面中,點擊你專案的儲存貯體,看到有一個新圖片就代表成功了! (如果AWS S3沒成功,請先在AWS S3上傳一個檔案,或是依照之前的設定重新設定一次) 步驟圖示說明 點擊我的安全登入資料 ![AWS security_credentials](https://i.imgur.com/olXbifd.png) 點擊存取金鑰,並建立新的存取金鑰 ![AWS token](https://i.imgur.com/34KJhBw.png) 填入金鑰和其他東西(要選擇production的tab) ![upload settings](https://i.imgur.com/7qlAshN.png) 上傳成功! ![upload success](https://i.imgur.com/NlQRXrc.png) :::info 備註: 更新strapi專案 一樣也是將檔案上傳到heroku並發布 路徑 - `./你的專案/` ```javascript= //CLI git add . git commit -m "strapi project changed..." git push heroku master //發布到heroku heroku open //開啟此專案的網站! ``` :::

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully