iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 19
1
自我挑戰組

Linux學習系列 第 19

Ubuntu apache2 html 、VirtualBox改成ssh連線

  • 分享至 

  • xImage
  •  

接著繼續
How To Install the Apache Web Server on Ubuntu 18.04

Step 4 — Managing the Apache Process

stop your web server:

sudo systemctl stop apache2

start the web server when it is stopped:

sudo systemctl start apache2

To stop and then start the service again(重新啟動):

sudo systemctl restart apache2

making configuration changes, Apache can often reload without dropping connections.(變更設定,不用重新啟動apache2):

sudo systemctl reload apache2

By default, Apache is configured to start automatically when the server boots. If this is not what you want, disable this behavior by typing(當電腦開機就會自動啟動網頁伺服器,如果不想自動啟動輸入以下指令):

sudo systemctl disable apache2

相反則是:

sudo systemctl enable apache2

Step 5 — Setting Up Virtual Hosts (Recommended)
就是要設定你網頁伺服器的網域名稱,但這個不是自己隨便亂打個hello.com之類的就可以用了,要兩件事
https://www.digitalocean.com/docs/networking/dns/
1 purchase a domain name from a domain name registrar(購買網域)
2 set up DNS records for your domain by using a DNS hosting service(設定DNS)

這邊應該蠻麻煩的,不過還是先照著步驟,以後再來了解,先假設我的網域叫
tedtedtedtedted.com
1 創建資料夾
2 chown user:group filename 更改filename的user和group
這邊的filename是/var/www/tedtedtedtedted.com/html
User是$USER,group是$USER
3 chmod 更改權限
這邊是把/var/www/tedtedtedtedted.com的權限改成755
4接著創建index.html
https://ithelp.ithome.com.tw/upload/images/20181101/20111994qKxnwGbFys.png

這邊就遇到問題了,因為VirtualBox沒辦法複製貼上,所以要打網頁就用手打,如果很多內容就很麻煩,所以這邊要來想辦法如何從windows的電腦複製文字到VirtualBox的Ubuntu伺服器

執行這個指令

sudo apt-get update && sudo apt-get install gpm(安裝滑鼠到linux伺服器)

但是會出現錯誤:

Package gpm is not available, but is referred to by another package.

為什麼?
gpm package not available
Repositories/Ubuntu

There are literally thousands of Ubuntu programs available to meet the needs of Ubuntu users. Many of these programs are stored in software archives commonly referred to as repositories. Repositories make it easy to install new software, while also providing a high level of security, since the software is thoroughly tested and built specifically for each version of Ubuntu.

repositories就像是軟體的貯藏室,可以讓安裝軟體變簡單,可以提供安全,每個軟體都有在不同版本的Ubuntu測試

有四個repositories:

Main - Canonical-supported free and open-source software.
Universe - Community-maintained free and open-source software.
Restricted - Proprietary drivers for devices.
Multiverse - Software restricted by copyright or legal issues.

所以就是因為Universe沒有允許,所以不能安裝gpm
解決方法:
How do I enable the “Universe” repository?

1 sudo add-apt-repository universe
2 sudo apt-get update
滑鼠開啟:sudo service gpm start
滑鼠關閉:sudo service gpm stop

接著就可以用滑鼠了,但是只能在自己的機器複製貼上,不能windows複製,然後在virtualbox貼上,接著試了這個方法
VirtualBox 5.2安裝Ubuntu 16.04與Windows 10共用剪貼簿
但出現這個畫面:
這不清楚為什麼,可能伺服器版本的linux不能用這個方法吧
https://ithelp.ithome.com.tw/upload/images/20181101/20111994Yki59SmBjz.png

接著找到了一樣的問題:
Ubuntu Server VM: copy paste?
解決方法:不用virtual的介面開虛擬機器了,改用putty的ssh連線

那怎麼改用putty的ssh連線呢?
Computer Networking Tutorial - 29 - Creating SSH Keys

首先要用ssh連線要在主機有公鑰,連線者要有私鑰,所以先產生一個公鑰和一個私鑰,然後把公鑰放在主機,給連線者私鑰

1產生公鑰和私鑰
puttygen.exe產生公鑰和私鑰
Generate-->把public key for pasting…放到主機-->save private key給連線者
https://ithelp.ithome.com.tw/upload/images/20181101/20111994CMDh2xk4E3.png
2怎麼把把public key for pasting…放到主機?
https://filezilla-project.org/
使用FileZilla
填寫以下內容
主機名稱
使用者
密碼
連接埠
連接埠使用22的話,防火牆記得要允許22
接個把公鑰貼到一個文字檔後存檔,檔名叫authorized_keys,不能有.txt
接著mkdir .ssh,然後就用FileZilla把公鑰丟過去
3 接著就開啟pageant.exe,然後把私鑰放入,接著在putty.exe,填寫hostname和port就可以連到主機了,就可以複製貼上囉

所以回到創建index.html
https://ithelp.ithome.com.tw/upload/images/20181101/20111994dxdQC9EkAk.png

接著

sudo nano /etc/apache2/sites-available/tedtedtedtedted.com.conf
DocumentRoot:網頁伺服器所顯示的html位置
ServerAdmin: administrator的email
ServerName:tedtedtedtedted.com
ServerAlias: www.tedtedtedtedted.com

https://ithelp.ithome.com.tw/upload/images/20181101/20111994KSXSLtZWIS.png
接著開啟

sudo a2ensite tedtedtedtedted.com.conf

,這個指令後基本上就可以把html放到網頁伺服器了,但是這邊要注意之前開過的html,像是原本的網頁,要執行這個指令

sudo a2dissite 000-default.conf

,取消原本的網頁,不然是沒辦法直接覆蓋原本的網頁,如果你還有更多的html曾經放到網頁伺服器上,那就要一個一個取消,最後在執行systemctl reload apache2就完成了
https://ithelp.ithome.com.tw/upload/images/20181101/20111994HFWE9S9kqD.png


上一篇
Linux dns-nameservers
下一篇
Ubuntu Apache2檔案和資料夾
系列文
Linux學習30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言