Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Windows + Docker 架設 Next.js HTTPS 網站

專案啟動流程

  1. 建立 .env 檔案
    MYSQL_ROOT_PASSWORD=...
    MYSQL_DATABASE=...
    MYSQL_USER=...
    MYSQL_PASSWORD=...
    
  2. 建立相關資料夾與檔案
    • db_data/:MySQL 資料庫資料夾
    • certbot/conf/:Let's Encrypt 憑證存放目錄
    • nginx-conf/site.conf:nginx 設定檔(請參考 site-template.conf),https 的區塊先暫時註解,等待申請憑證後再取消註解。
    • nextjs-app/Dockerfile:Next.js 應用 Dockerfile
  3. 啟動 Docker 服務
    docker-compose up -d
  4. 申請 SSL 憑證(首次部署時)
    • 使用 win-acme 工具申請 Let's Encrypt 憑證。(run as administrator)
      • [M]: Create certificate (full options)
      • [2]: Manual input
      • Host: 輸入你的網域名稱,例如 yourdomain.ddns.net
      • [1]: Separate certificate for each domain (e.g. *.example.com)
      • [6]: [dns] Create verification records manually (auto-renew not possible)
      • [2]: RSA key
      • [2]: PEM encoded files (Apache, nginx, etc.)
      • File path: 輸入 <path to this project>/certbot/conf/
      • 接著都照預設選項即可。
    • 完成後,會在 certbot/conf/ 目錄下生成憑證檔案。
      • yourdomain.ddns.net-chain.pem:憑證檔案 (範例)
      • yourdomain.ddns.net-key.pem:私鑰 (範例)
  5. 編輯 nginx-conf/site.conf
    • 取得憑證後,取消註解 HTTPS 相關區塊,並確認 ssl_certificate 路徑正確。
    • 重新啟動 nginx 服務:
      docker-compose restart nginx
  6. 測試網站
    • 確認 docker 服務皆以啟動:(應該看到 appdbwebproxy 三個服務)
      docker-compose ps
    • 在瀏覽器中輸入 https://yourdomain.ddns.net,確認網站可以訪問。

目錄結構重點

  • nextjs-app/:Next.js 應用原始碼與 Dockerfile
  • nginx-conf/:nginx 設定檔
  • certbot/:Let's Encrypt 憑證與驗證目錄
  • db_data/:MySQL 資料庫資料夾

About

Build a dynamic website on Windows using Docker, Nginx, Next.js, and MariaDB.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages