--- 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 ```  > 看到 **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了  ## 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) 看到下圖表是成功囉  - 查看apache設定檔  - 到`/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  - 建立 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/) -  >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://app.sli.do/event/pr48dibw)
×
Sign in
Email
Password
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