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: 1091, lsa --- - Book mode https://hackmd.io/@ncnu-opensource/book Week 07(2020/11/05) === [即時聊天室](https://app.sli.do/event/pr48dibw) ## lighttpd ### 安裝方式 - `sudo apt update` - `sudo apt install lighttpd` ### virtual host設定方式 - 在 `/etc/lighttpd/conf-available` 實作 virtual host: - 檔名前面的數字代表起始順序 ```shell= sudo vim 99-lighttpd1.conf ``` ```shell= $HTTP["host"] =~ "lighttpd1.com" { server.document-root = "/var/www/vhost/lighttpd1" } ``` ```shell= sudo vim /etc/hosts ``` - 新增 domain ``` 127.0.0.1 lighttpd1.com ``` - 建立網站根目錄 - 可以在/var/www檢查是否有 vhost 的資料夾 ```shell= sudo mkdir /var/www/vhost/lighttpd1 ``` - 進入html,寫入下方文字 ```shell= sudo vim /var/www/vhost/lighttpd1/index.html ``` - 以下內容會顯示在 lighttpd1.com:8081 的網頁上 ```shell= vhost: lighttpd1.com ``` - 進入互動模式 看未被啟用的設定檔有哪些 ```shell= #enable lighttpd config sudo lighttpd-enable-mod Enable module: lighttpd1 ``` ```shell= sudo service lighttpd force-reload ``` - 做重大改變時要先關掉(確保設定有確實被lighttpd吃到) ```shell= sudo service lighttpd stop ``` - 關掉之後可以確認一下狀態 ```shell= sudo service lighttpd status ``` - 把 `server.port` 改成 8081 port ```shell= sudo vim /etc/lighttpd/lighttpd.conf ``` - 檢查看跑在哪個port上 (要看到 lighttpd 跑在 8081) ```shell= sudo netstat -ntupl ``` `看不到 nginx 是正常的 因為沒有開啟服務` ### 實作proxy_pass - 將lighttpd收到的請求轉給proxy ( 其他的 virtual host ) - Virtual Host 很弱的狀況下 (只有一個IP位址) - 分散眾多使用者的要求,減輕loading - Virtual Host 很強大狀況下 - 接收其他 Virtual Hosts 的請求 ```shell= sudo vim /etc/lighttpd/conf-available/99-lighttpd2-proxy.conf ``` - 比對到請求的 host == "lighttpd2.proxy.com" > lightppd網址無法辨識底線喔,犯了用底線的低級錯誤就會像我一樣經過一整夜還是得到400 error無法把作業寫出來喔 ```conf= server.modules += ( "mod_proxy" ) $HTTP["host"] == "lighttpd2.proxy.com" { proxy.balance = "hash" proxy.server = ( "" => (("Host" => "127.0.0.1", "port" => "8080",))) } ``` > proxy.server:將request pass給127.0.0.1:8080的server ```shell= sudo lighttpd-enable-mod Enable module: lighttpd2-proxy ``` ![](https://i.imgur.com/zkmDdz1.png) > 看到 **OK** 代表enable完成 - 檢查一下 ```shell= ls -l /etc/lighttpd/conf-enabled/ ``` - reload並檢查status ```shell= sudo service lighttpd force-reload sudo service lighttpd status ``` - 到 `sudo vim /etc/hosts` 新增host name ```shell= 127.0.0.1 lighttpd2.proxy.com ``` - 在firefox看一下: `http://lighttpd2.proxy.com:8081/`(nginx記得開) - port號:8081是lighttpd的,但可看到實際上被我們pass到nginx了 ![](https://i.imgur.com/Hn8KcsX.png =400x) ## apache2 ```shell= sudo apt install apache2 ``` ```shell= sudo service apache2 start ``` - 確認 apache2 有沒有跑起來 ```shell= sudo service apache2 status ``` - 看一下 apache2 在哪個 port ```shell= sudo netstat -nptul ``` - firefox上輸入`127.0.0.1`(預設80port) 看到下圖表是成功囉 ![](https://i.imgur.com/qS5uknR.png =400x) - 查看apache設定檔 ![](https://i.imgur.com/lxqKq9u.png=300x) - 到`/etc/apache2/` 設定apache服務 - apache2.conf: 主要設定檔 - mods-available、mods-enable: 提供的許多modules - port.conf : apache 預設 port 的地方 - envvars: 定義所有環境變數 - 查看apache2的組態設定檔 ```shell= vim /etc/apache2/apache2.conf ``` - 查看apache2提供的moduel - ex: 查看user ```shell= ls -l mods-available/ |grep user ``` - enable modules: `userdir` - mod功能:把網頁跟目錄設定在使用者HOME目錄底下 ```shell= sudo a2enmod userdir ``` - 重新啟動apache2 ```shell= sudo systemctl restart apache2 ``` - 查看一下 `userdir`的組態檔 ```shell= vim mods-available/userdir.conf ``` - (回到家目錄)建立一個 public_html ```shell= mkdir public_html ``` - 建立index.html ```shell= vim index.html ``` - 在網址輸入 `127.0.0.1/~<username>/` - 讀取家目錄下的public_html - cd 到 `/etc/apache2/sites-available` - http : `000-default.conf` - https :`default-ssl.conf` :::warning 除了nginx外,lighttpd、apache 設定檔都需要加上 `.conf` ::: #### [lab] domain name - 用domainname轉virtualHost - 聽所有 8082 port - 聽的 server name = apache1.com - 新增網站組態: `sudo vim /etc/apache2/site-available/apache1.conf` ```shell= <VirtualHost *:8082> DocumentRoot /var/www/vhost/apache1 ServerName apache1.com </VirtualHost> ``` - 先停掉apache2 ```shell= sudo service apache2 stop ``` - 到`/etc/apache2`的 `ports.conf`增加Listen的port ```shell= sudo vim ports.conf ``` - 把要Listen的port加進去 `Listen 8082` - 再把 apache2 開啟 ```shell= sudo service apache2 start ``` - 可以先用`sudo netstat -ntupl` 檢查apache2的port - 到firefox輸入`127.0.0.1:8082` 查看一下是否有導到apache2 ![](https://i.imgur.com/EeHCYff.png =400x) - 建立 DocumentRoot: 到 `/var/www/vhost` 下建立資料夾 apache1(DocumentRoot) ```shell= sudo mkdir apache1 ``` - 增加一筆 Domain 對應 IP 的紀錄 ```shell= sudo vim /etc/hosts ``` ```shell= 127.0.0.1 apache1.com ``` - enable設定檔 ```shell= sudo a2ensite apache1(你要啟動的設定檔) ``` ```shell= sudo systemctl reload apache2 ``` - 確認 apache2 為 running 狀態 ```shell=ㄎ sudo service apache2 status ``` - 到 `/var/www/vhost/apache1`下,輸入你想要呈現在網頁上的內容 ```shell= sudo vim index.html ``` ```shell= sudo service apache2 reload ``` - 確認為active - 到firefox裡輸入 `apache1.com:8082/` 檢查一下是否有`index.html`的內容 ### 使用nginx 建立Load Balance分流機制 (11/12課程) [Load Balance](https://zh.wikipedia.org/zh-tw/%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1) - 路徑:`/etc/nginx/sites-enabled` ```shell= sudo vim lab ``` - 在`/etc/nginx/sites-available`下 `sudo vim lab` ```shell= upstream backend { server nginx1.com:8083; server nginx2.com:8084; } server { listen 8080; serverName works.lab.com; location /{ proxy_pass http://backend; } } ``` - 未完待續 大家加油:) ## Wordpress 安裝 - [Wordpress](https://tw.wordpress.org/) - ![](https://i.imgur.com/d5Ngtno.png) >wiki: 以PHP和MySQL為平台的自由開源的部落格軟體和內容管理系統 - 他是一種內容管理系統 - 特點 - 如果你想架網站但是不會用,可以使用它 - 有相當多的佈景主題'附加外掛等免費資源可供下載運用 - 繁體中文化程度已經達百分之百 - 針對 WordPress 所寫的教學文章相當多樣性而豐富 ### 裸機安裝WordPress - 增加 PPA - Ubuntu 中的 PPA (Personal Package Archives) 是 Ubuntu Launchpad 網站提供的一項服務,允許 Ubuntu 個人用戶上傳打包好的套件,讓其他 Ubuntu 使用者可以下載和更新。 ```shell= sudo add-apt-repository ppa:ondrej/php ``` - 安裝所需套件 - mariadb資料庫 - nginx為server ``` shell= sudo apt install mariadb-server nginx php7.4-fpm php7.4-mysql ``` - 下載 wordpress ``` shell= sudo wget https://tw.wordpress.org/wordpress-5.5.1-zh_TW.tar.gz ``` - 解壓縮 ```shell= tar -xvf wordpress-5.5.1-zh_TW.tar.gz ``` - 將wordpress移到 /var/www/下 (通常軟體的紀錄檔都會放到這個目錄底下) ``` shell= sudo mv wordpress /var/www ``` - 設定 wordpress ``` shell= sudo mysql -u root ``` - 建立一個database讓wordpress使用 - 要一行一行的輸入 ```sql= CREATE DATABASE wordpress; -- 有誰有權限去讀 wordpress GRANT ALL PRIVILEGES ON wordpress.* TO "wordpress_user"@"localhost" -- 他的密碼 IDENTIFIED BY "wordpress_password_1234"; FLUSH PRIVILEGES; EXIT ``` - 設定 nginx 設定檔 在`/etc/nginx/sites-available`下 `sudo vim wordpress.conf` ```conf= server { listen 80; listen [::]:80; root /var/www/wordpress; index index.php; server_name lsa.xxx.org; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; } location ~ /\.ht { deny all; } } ``` ```shell= sudo vim /etc/hosts 127.0.0.1 lsa.xxx.org ``` - 講解跑的流程 (user group) ```shell= cat /etc/php/7.4/fpm/pool.d/www.conf ``` - 重啟 nginx ```shell= # 檢查是否有錯誤 sudo nginx -t # 重啟 nginx sudo nginx -s reload ``` ```shell= cd /etc/nginx/sites-enabled/ ``` ```shell= sudo ln -s ../sites-available/wordpress.conf wordpress.conf ``` - 重啟 nginx ```shell= sudo nginx -s reload ``` - 用 firefox(chrome也可以) 開啟`lsa.xxx.org`就可以安裝 - 跟著上面做的 - 帳號是`wordpress_user` - 密碼是`wordpress_password_1234` ```shell= # 要先到這個目錄底下 cd /var/www/wordpress ``` ```shell= # 開啟它放進很長一串的資料(如圖 sudo vim wp-config.php ``` ![](https://i.imgur.com/zMUx3s7.png =400x) [即時聊天室](https://app.sli.do/event/pr48dibw)

    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