在 Ubuntu 22.04 上安裝 Nginx

安裝 Nginx

    
sudo apt update && sudo apt install -y nginx
    

驗證安裝:
    
nginx -v
nginx version: nginx/1.18.0 (Ubuntu)
    

確認 nginx 是否啟動
    
systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2023-03-25 15:06:36 UTC; 24h ago
       Docs: man:nginx(8)
    Process: 16203 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 16204 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 16205 (nginx)
      Tasks: 5 (limit: 28700)
     Memory: 4.7M
        CPU: 87ms
     CGroup: /system.slice/nginx.service
             ├─16205 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ├─16206 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
             ├─16207 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
             ├─16208 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
             └─16209 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">

Mar 25 15:06:36 ruyut-app systemd[1]: Starting A high performance web server and a reverse proxy server...
Mar 25 15:06:36 ruyut-app systemd[1]: Started A high performance web server and a reverse proxy server.
    

常用指令
    
sudo systemctl start nginx   # 啟動 nginx
sudo systemctl stop nginx    # 停止 nginx
sudo systemctl restart nginx # 重新啟動 nginx
sudo systemctl reload nginx  # 不中斷服務直接套用設定檔

sudo systemctl enable nginx  # 系統啟動時自動啟動 nginx
sudo systemctl disable nginx # 系統啟動時不自動啟動 nginx

sudo nginx -t        # 驗證 nginx 設定檔
sudo nginx -s reload # 套用設定檔
    

使用瀏覽器輸入主機 ip 連入時會看到 nginx 的預設頁面:
    
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.
    

nginx 預設頁面路徑:
    
/var/www/html/index.nginx-debian.html
    

nginx 預設設定檔:
    
/etc/nginx/nginx.conf
    

留言