NCNU-OpenSource
      • 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
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners 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
    • 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 Help
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
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners 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
    ###### tags: `1111` `lsa` `ncnu` # Week 08 (2022/11/03) [TOC] - Book mode: https://hackmd.io/@ncnu-opensource/book --- - `/var/www`: 瀏覽器預設畫面 ![](https://i.imgur.com/jGbyAxa.png) 新增html 將nginx路徑存在裡面 ## Virtual Host - 主要分為 name-based 以及 IP-based - 在一個server上託管多個網站,網站與網站間共享一個server的記憶體、CPU、設定檔等 - 不浪費 server 資源,最大化利用價值 - demo ```= telnet ammon.bluet.org 80 GET / HTTP / 1.0 ``` ```= <head><title>BlueT.org Studio</title></head> ``` 更改Host ### Name-based Virtual Host - 在同一server上架有多個不同的網站,不同網站間依據名稱判定 - 名稱就是是使用者輸入的FQDN - 一個網站也可以 match 到不止一組的 domain name ### IP-based - 在一台主機上,開設多個IP位址的虛擬主機,可以針對只聽特定的網卡 - ![](https://i.imgur.com/wI8vTb3.png) :::info **Port-based Virtual Host** 利用 port 來區別不同的網站,因為不會在常見的 port 上,可以用在內部或私人使用 ::: ### Lab1 實作 1. 進入 `cd /var/www` - 建立資料夾 vhost - `sudo mkdir vhost` - 進入 `/var/www/vhost`,然後建立資料夾 `nginx1` - `sudo mkdir nginx1` - 在裡面新增一個 html - `sudo vim index.html` 2. 再去`sudo vim /etc/hosts`新增一個 host 的紀錄 ![](https://i.imgur.com/S2o6A5o.png) 3. 在sites-available 複製`default`,並命名為 `nginx-vhost` - `sudo cp -a default nginx-vhost` > `-a`: 複製檔案權限 4. 改nginx.vhost裡的**port**、**root**、**server_name** ![](https://i.imgur.com/6AJs1qn.png) > port 的第一行設定是 IPv4 ;第二行是 IPv6 5. 把 /etc/nginx/sites-available/nginx-vhost ==softlink== 到 /etc/nginx/site-enabled - `sudo ln -s /etc/nginx/sites-available/nginx-vhost /etc/nginx/sites-enabled/` 6. 確認 softlink 有沒有成功 - `ls -l /etc/nginx/sites-enabled` ![](https://i.imgur.com/pXEMpBZ.png) > softlink 到 enabled 裡的檔案是服務啟動時會用到的檔案 7. 確認是不是能正常運行,不會崩潰 - `sudo nginx -t` 8. 確認完狀態`sudo service nginx status`是 active 的話,重新讀取設定檔 - `sudo service nginx reload` - `sudo service nginx reload` = `sudo service nginx stop` + `sudo service nginx start` - 如果 reload 之後沒有改變 可以下 `sudo service nginx restart` 重新開機 9. 開啟瀏覽器,確認是否連線成功 - 如果 domain name 是數字開頭會導到搜尋,前面要加 `http://` 才能成功導向 127.0.0.1 - `http://<domain_name>:<port>` ## Reverse Proxy & Load Balance :::info Forward Proxy ![](https://i.imgur.com/H0kStTI.png) - 代理 : client 會透過 proxy 向 server 發出request 因為以前頻寬很貴~,個人電腦都連到 proxy ,proxy 再統一發出request - 同時,proxy 還可以有 **快取** 的功能: ::: ### Reverse proxy 反向代理 - 將 client提出的 request 發給不同的 server 處理 ![](https://i.imgur.com/8aigT3z.png) - 可以快取 - 有使用 Reverse proxy - proxy $\to$ server - 沒有使用 Reverse proxy - 直接到 server ### Lab2 實作 1. 先停止服務 - `sudo service nginx stop` 2. 確認 nginx 服務狀態 - `sudo nginx -t` 3. 進到 `/etc/nginx/sites-available/` 裡的設定檔 nginx-vhost 新增一個 proxy_pass ![](https://i.imgur.com/UdVBWj7.png) 4. 重啟服務 - `sudo service nginx start` 5. 開啟瀏覽器,確認是否連線成功 - 網址與 Lab1 實作相同 ## Load Balance 負載平衡 - Reverse Proxy 的一個功能 - 負載平衡: 將流量合理分配,以提升各 server 的使用率及可用性 - 避免流量集中給同一個server而造成超載/過載/爆掉而使服務無法正常運行 - 避免 server 開著卻沒有用而造成浪費 ### Lab3 實作 1. 在 `/etc/nginx/sites-available` 目錄下新增ㄧ個檔案 - `sudo vim nginx_loadbalance` - 內容: ```= upstream lsa.lab { server lsa.kija.io; server tw.search.yahoo.com.; } server { listen 8070; server_name nginx1.loadBalance.com; location / { proxy_pass http://lsa.lab; } } ``` > 註記: > proxy_pass `http:// lsa.lab`的 `lsa.lab`要與上方 upstream 後面接的網址 `lsa.lab` 相同 2. softlink - `sudo ln -s /etc/nginx/sites-available/nginx_loadbalance /etc/nginx/sites-enabled/` 3. 確認設定檔狀 > `sudo nginx -t` 4. 重啟服務 5. `sudo vim /etc/hosts` 新增host紀錄 > `nginx1.loadBalance.com:8070` 6. 開啟瀏覽器測試 >一直按重新整理,如果可以輪流跳轉至 `lsa.kija.io`、`tw.search.yahoo.com` >兩個頁面就代表成功囉! :::info upstream - 利用 Round Robin 的方式去分散流量 - 定義用的 IP :::

    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