Jackson
  • 請先讀我
  • 目錄
  • LYNX INDOOR2
    • LYNX INDOOR 2
    • 歡迎
    • 讓我們開始吧
    • 01. 放置攝影機
    • 02. 攝影機供電
    • 03. 下載 TEND SECURE APP
    • 04. 啟動 TEND SECURE APP
    • 攝影機 LED 燈
    • 有限的兩年製造商的保修
  • Vim
    • 序
    • 安裝
    • 普通模式指令
      • 移動
      • 搜尋
      • {motion}
      • 視窗、標籤頁、緩衝區
      • 拼寫檢查器
      • 文件管理器
    • 可視模式
    • 插入模式指令
    • Ex命令模式指令
      • 自動補齊
      • [range] {address}
      • 視窗、標籤頁
      • 緩衝區
      • 暫存器
      • ex-flags
      • Quickfix
      • tags
      • 文件管理器
    • 終端模式
    • 搜尋模式指令
      • {pattern}
      • magic
    • 環境設定
      • 環境變數
      • 映射
      • try catch
      • autocmd
      • 編輯器高亮顏色
    • 設定 help 文件中文版
    • 交換文件
    • 比較檔案
      • 解決 git 衝突
    • 函數庫
    • 插件推薦
      • 代碼
        • vim-snippets
        • coc
          • coc-snippets
          • coc-phpls
          • coc-json
          • ccls
          • VimScript Language Server
          • coc-prettier
        • deoplete
        • ale
          • C
          • HTML
          • Javascript
        • tabnine
        • php-cs-fixer
        • NERD Comment
        • ctags
      • 外觀
        • Dracula
        • NERDTree
        • airline
        • css color
        • coc-explorer
        • purity
        • startify
        • vim-mundo
      • 插件管理器
        • vim-plug
        • 原生插件管理
        • Vundle
      • Git
        • vim-fugitive
        • gv.vim
      • 分析插件
      • surround
      • Auto Pairs
      • visual-star-search
      • vim-tmux-navigator
    • 什麼是 vimrc
      • 設定檔案配置
      • ftplugin
  • 終端
    • 序
    • bash 腳本
      • 基礎
      • 環境變數
      • 正規表示式
      • 參數
      • 常用內建指令
        • 輸出
        • 捕捉中斷
        • shell 選項
      • 條件判斷
      • 迴圈
      • 函式
      • Windows 上使用 bash
      • 更新 bash
    • 指令
      • bash
        • 程序
        • 使用者與群組
        • 分析網路,檢測並與網路介面卡進行互動
        • 查看檔案與目錄
        • 建立與修改檔案或目錄
        • 搜尋
        • 壓縮與打包
        • 備份
        • 重導向
        • 寄信
        • 操作終端機
        • 另外安裝的指令
          • jq JSON 剖析器
          • wget
      • zsh
        • alias
      • Linux
        • 排程
      • 目錄路徑
      • 萬用字元
    • tmux
      • 未進 tmux 的終端指令
      • 進入到 tmux 指令
      • 進入到 tmux 的快捷鍵
      • 命令提示指令
      • 配置 tmux
      • 插件推薦
        • 插件管理器
        • vim-tmux-navigator
    • 插件推薦
      • 外觀
        • Gogh
        • purity
        • Dracula
        • powerline
      • zsh
        • zsh-syntax-highlighting
        • zsh-autosuggestions
  • Git
    • 序
    • 常用指令
    • 切換帳號
  • 作業系統
    • kali
      • 快捷鍵
      • E: unable to locate package
      • 中文亂碼和中文輸入
      • 命令提示字元修改成 Windows 格式
    • mac os
      • 架站 MAMP
        • Apache
        • PHP
        • MySQL
        • phpMyAdmin
        • localhost https
    • Ubuntu
      • 安裝 PHP
      • 安裝 Nginx
  • AWS
    • 序
    • Amazon EC2
  • WordPress
    • localhost ftp 連線問題
    • 強制修改信箱帳號
    • bitnami 登入 Wordpress
  • 影片剪輯
    • 序
    • 自動生成字幕
  • 其它
    • 鍵盤符號中英文
Powered by GitBook
On this page
  • 介紹
  • 設定
  • 設定伺服器
  • 建立憑證
  • 信任憑證
  • 參考

Was this helpful?

  1. 作業系統
  2. mac os
  3. 架站 MAMP

localhost https

介紹

http 和 https 的差別在於,後者是安全的傳輸協定 本篇介紹如何在本機端使用 https

設定

要使用 https 總共有三個步驟

  1. 設定伺服器 (例如 Apache)

  2. 建立憑證

  3. 信任憑證

設定伺服器

將 /usr/local/etc/httpd/httpd.conf 的一些註解 # 移除掉 如下所示

/usr/local/etc/httpd/httpd.conf
LoadModule socache_shmcb_module lib/httpd/modules/mod_socache_shmcb.so
LoadModule ssl_module lib/httpd/modules/mod_ssl.so
Include /usr/local/etc/httpd/extra/httpd-ssl.conf

將 /usr/local/etc/httpd/extra/httpd-ssl.conf 監聽埠號 Listen 8443 改成 Listen 443

/usr/local/etc/httpd/extra/httpd-ssl.conf
Listen 443

將 /usr/local/etc/httpd/extra/httpd-ssl.conf <VirtualHost default_:8443> 和下面的 ServerName www.example.com:8443 8443 改成 443 並將 <VirtualHost default_:8443> 下面的這兩行程式碼註解 DocumentRoot "/usr/local/var/www" ServerName www.example.com:8443

/usr/local/etc/httpd/extra/httpd-ssl.conf
<VirtualHost _default_:443>

#   General setup for the virtual host
#DocumentRoot "/usr/local/var/www"
#ServerName www.example.com:443

到 /usr/local/etc/httpd/extra/httpd-vhosts.conf 建立一個 virtual host

/usr/local/etc/httpd/extra/httpd-vhosts.conf
<VirtualHost *:443>
    DocumentRoot "/Users/yourName/www"
    ServerName localhost
    SSLEngine on
    SSLCertificateFile "/usr/local/etc/httpd/server.crt"
    SSLCertificateKeyFile "/usr/local/etc/httpd/server.key"
</VirtualHost>

DocumentRoot 網站檔案的目錄 ServerName 伺服器名稱 SSLCertificateFile 憑證的檔案位置 SSLCertificateKeyFile 憑證鑰匙的檔案位置

建立憑證

在 /usr/local/etc/httpd 資料夾底下 建立憑證設定檔 ssl.conf

/usr/local/etc/httpd/ssl.conf
[req]
prompt = no
default_md = sha256
default_bits = 2048
distinguished_name = dn
x509_extensions = v3_req

[dn]
C = TW
ST = Taiwan
L = Taipei
O = YourCompany Inc.
OU = IT Department
emailAddress = example@example.com
CN = localhost

[v3_req]
subjectAltName = @alt_names

[alt_names]
DNS.1 = localhost
DNS.2 = 127.0.0.1

[dn] 為憑證的相關資訊 C 國家名稱 ST 州或省名稱 L 地區名稱 O 機構名稱(公司名稱) OU 組織單位名稱(公司部門) emailAddress 電子郵件 CN 通用名(伺服器名稱)

上面建立 VirtualHost 的 ServerName 為 localhost 所以 CN 設為 localhost

[alt_names] 為域名 可以視你的需求多設定幾個 目前需要的是本機端,所以設定 localhost 和 127.0.0.1

因為上面設定 SSLCertificateFile 位置在 /usr/local/etc/httpd 資料夾底下 所要先切換到指定資料夾再建立憑證

$ cd /usr/local/etc/httpd $ openssl req -x509 -new -nodes -sha256 -utf8 -days 3650 -newkey rsa:2048 -keyout server.key -out server.crt -config ssl.conf

建立好之後測試看看,有沒有問題

$ sudo apachectl configtest

沒有問題的話就重啟伺服器

$ sudo apachectl -k restart

重啟之後可以看 /usr/local/var/log/httpd/error_log 有沒有錯誤訊息

信任憑證

以下是 mac 信任憑證的方法

接下來會看到 localhost 憑證,並將它打開

接下來就能使用 https://localhost 了

參考

PreviousphpMyAdminNextUbuntu

Last updated 5 years ago

Was this helpful?

極速打造 https://localhostMedium
打開鑰匙圈存取
輸入項目選擇剛剛建立的 server.crt
打開信任,選擇永遠信任
macOS 12.0 Monterey Apache Setup: LetsEncrypt SSLGrav CMS
如何使用 OpenSSL 建立開發測試用途的自簽憑證 (Self-Signed Certificate) | The Will Will Web
Logo
Logo
Logo