Jump to content

3.安裝Nginx,之後申請SSL憑證 / 更改主機名


Jack

Recommended Posts

Posted (edited)

---------------------------------
安裝Nginx,之後申請SSL憑證
---------------------------------

apt update


apt upgrade -y


apt dist-upgrade -y


apt install curl vim wget gnupg dpkg apt-transport-https lsb-release ca-certificates


增加GPG Key
curl -sSL https://n.wtf/public.key | gpg --dearmor > /usr/share/keyrings/n.wtf.gpg

 

加入Nginx QUIC 源
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

 


更新並安裝nginx
apt update


apt install nginx-extras -y

 


瀏覽nginx版本
nginx -V

 

將顯示 nginx version: nginx-n.wtf/1.25.4

 

 

 

----------------------------
更改主機名
----------------------------

更改主機名
hostnamectl set-hostname 域名.com


重開機
reboot


再次SSH登入

將顯示 Linux 域名.com 6.1.0-21-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.90-1 (2024-05-03) 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 index.php;

        server_name 域名;

        location / {
                try_files $uri $uri/ =404;
        }
}


ESC儲存並離開
:wq

 


軟連結到 /etc/nginx/sites-enabled 目錄,讓它生效
ln -s /etc/nginx/sites-available/域名.com.conf /etc/nginx/sites-enabled/域名.com.conf

 


重新加载Nginx
nginx -t


nginx -s reload

 


在網站目錄中,新增一個index.html
vi /var/www/域名.com/index.html


在此檔案中,複製貼上
Just test

 

ESC儲存並離開
:wq

 

開機啟動nginx
systemctl enable nginx


啟動nginx
systemctl start nginx


重開機
reboot

 

瀏覽nginx狀態
systemctl status nginx

 

按 ctrl + z 停止

 

 

這時,瀏覽器可進入你的網站
http://域名.com/

 

接下來申請SSL憑證

 

Edited by Jack
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...