January 18Jan 18 安裝第三方Nginx 1.29、更改主機名--------------- 安裝Nginx --------------- 本教學適用於 Debian 13 (需root權限),假設系統尚未安裝Nginx 此來源 https://n.wtf/ 提供第三方 Nginx(目前為 1.29.x),若想使用 Debian 官方版本可略過此步 增加 https://n.wtf GPG Key curl -sSL https://n.wtf/public.key | gpg --dearmor > /usr/share/keyrings/n.wtf.gpg 加入 https://n.wtf/ 的Nginx源 echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/n.wtf.gpg] https://mirror-cdn.xtom.com/sb/nginx/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/n.wtf.list apt update apt install zip unzip apt install curl vim wget gnupg dpkg apt-transport-https lsb-release ca-certificates 安裝nginx apt install nginx-extras -y 瀏覽nginx版本,顯示 nginx version: nginx-n.wtf/1.29.4 nginx -V ---------------------------- 更改主機名 ---------------------------- 更改主機名,修改 hostname 可能影響提示字元或部分服務,非必要可略過 hostnamectl set-hostname 域名.com 離開SSH exit 再次SSH登入 將顯示為 Linux 域名.com 6.12.63+deb13-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.63-1 (2025-12-30) x86_64 ---------------------------- 配置Nginx ---------------------------- 預設網站目錄 mkdir -p /var/www/域名.com 新增 域名.com.conf vi /etc/nginx/sites-available/域名.com.conf server { listen 80; root /var/www/域名.com; index index.html index.htm; server_name 域名.com; location / { try_files $uri $uri/ =404; } } ESC儲存並離開 :wq 若 /etc/nginx/sites-enabled/ 已存在其他網站,請先確認不衝突 軟連結到 /etc/nginx/sites-enabled 目錄,讓它生效 ln -s /etc/nginx/sites-available/域名.com.conf /etc/nginx/sites-enabled/域名.com.conf 重新載入Nginx nginx -t systemctl reload nginx 在網站目錄中,新增一個index.html vi /var/www/域名.com/index.html 在此檔案中,複製並貼上 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>TEST</title> </head> <body> TEST </body> </html> ESC儲存並離開 :wq ---------------------------------- 開機啟動Nginx ---------------------------------- 開機啟動 systemctl enable nginx 啟動 systemctl start nginx 重開機 reboot 確認開機有自動啟動nginx,顯示 Active: active (running) systemctl status nginx 這時,瀏覽器可進入你的網站 http://域名.com/index.html
Create an account or sign in to comment