Appreciate, respect and accept it, don't take it for granted

就決定是你了! Apache

2021-01-29

從可以動的Apache開始吧

OS環境: Ubuntu 20.04, 安裝apache

1
2
sudo apt update
sudo apt install apache2

設定j2hongming.dev

1
2
3
sudo mkdir -p /var/www/j2hongming.dev/public_html
sudo chown -R $USER:$USER /var/www/j2hongming.dev/public_html
sudo vim /etc/apache2/sites-available/j2hongming.dev.conf

j2hongming.dev.conf的內容

1
2
3
4
5
6
7
8
<VirtualHost *:80>
ServerAdmin admin@j2hongming.dev
ServerName j2hongming.dev
DocumentRoot /var/www/j2hongming.dev/public_html

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

啟用j2hongming.dev.conf設定檔, 關閉預設設定檔000-default.conf, 原因是設定檔順序為字母排序, 若同時開啟且使用ip存取的話, 會載入000-default.conf的設定
重新載入設定

1
2
3
4
sudo a2ensite j2hongming.dev
# optional, stop default
sudo a2dissite 000-default.conf
systemctl reload apache2

編輯首頁

1
sudo vim /var/www/j2hongming.dev/public_html/index.html

index.html的內容

1
2
3
4
5
6
7
8
9
10
<!doctype html>
<html>
<head>
<title>Hi, I'm j2hongming</title>
</head>
<body>
Welcome! This is j2hongming.dev
<p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p>
</body>
</html>

因為還沒申請網域, 本機先修改host試試看吧, windows系統的位置%SystemRoot%\System32\drivers\etc\hosts, linux系統的位置/etc/hosts

改好了, 但好像沒反應, 使用curl http://j2hongming.dev可以但使用瀏覽器不行QQ

查了一下似乎是因為HSTS, 目前還沒仔細研究這個東西, 等我們幫HTTP加上s再來試試

參考


Blog comments powered by Disqus