在前面章節(安裝基本網路服務(使用Apache))已經裝了Apache2

也看到了Apache2 Debian Default Page這是安裝完成後預設產生的歡迎頁面

其實內容就是在介紹主要會用到的檔案安裝路徑與功能

Image 070

 

 

Apache服務控制

還記得安裝好Apache2直接輸入IP就看到網頁,但如果重開VM後你會發現怎麼找不到網頁了

這是因為安裝程序自動幫我們把服務(Service)啟動了,但重開後並沒有啟動

以下記錄幾個常用的指令

停止Apache服務 sudo service apache2 stop
啟動Apache服務 sudo service apache2 start
重啟Apache服務 sudo service apache2 restart

附註:service指令需要較高權限,若沒有加sudo會出現 -bash: service: command not found 的錯誤

 

 

網頁路徑

Apache2安裝的路徑在 /var/www/html  

輸入 cd /var/www/html/ 移動到目錄中

輸入  ls 列出目錄中的檔案,可以看到index.html,沒錯這就是我們看到的Apache2 Debian Default Page

 

修改網頁

這邊參考官方文件,編寫一個顯示Hello World的網頁,輸入指令(整行無段行)

echo '<!doctype html><html><body><h1>Hello World!</h1></ body></html>' | sudo tee /var/www/html/index.html

這段的意思就是把那一大串html程式碼寫入到 /var/www/html/index.html ,因此原本的檔案內容就被取代掉了

接下來重新在瀏覽器輸入IP顯示網頁,就變成Hello World!了

arrow
arrow
    創作者介紹
    創作者 Robarter 的頭像
    Robarter

    羅巴特

    Robarter 發表在 痞客邦 留言(0) 人氣()