Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

Nginx 安裝路徑與配置文件結構速查表

編輯:關於伺服器

標準安裝路徑(源碼編譯默認)

類別路徑說明
程序主目錄/usr/local/nginx二進制、模組、HTML 默認根目錄
主配置文件/usr/local/nginx/conf/nginx.conf核心配置入口
虛擬主機配置目錄/usr/local/nginx/conf/vhost/建議每站點一個 .conf 文件
單站點配置/usr/local/nginx/conf/vhost/域名.conf如 example.com.conf
日誌目錄/usr/local/nginx/logs/access.log、error.log
PID 文件/usr/local/nginx/logs/nginx.pid主進程 ID
臨時文件目錄/usr/local/nginx/client_body_temp/ 等proxy、fastcgi、uwsgi、scgi 緩存

關鍵文件結構示例


/usr/local/nginx/
├── conf/
│   ├── nginx.conf              # 主配置
│   ├── mime.types              # MIME 類型映射
│   ├── fastcgi_params          # FastCGI 參數
│   ├── proxy.conf              # 反向代理通用配置
│   ├── ssl/                    # SSL 證書目錄
│   └── vhost/                  # 虛擬主機配置
│       ├── example.com.conf
│       ├── api.example.com.conf
│       └── default.conf        # 默認站點
├── sbin/
│   └── nginx                   # 主程序二進制
├── modules/                    # 動態模組
├── html/                       # 默認站點根目錄
├── logs/
│   ├── access.log
│   ├── error.log
│   └── nginx.pid
└── temp/                       # 臨時文件(可單獨掛載磁盤)
    ├── client_body_temp
    ├── proxy_temp
    ├── fastcgi_temp
    ├── uwsgi_temp
    └── scgi_temp

常用操作命令

操作命令
語法檢查/usr/local/nginx/sbin/nginx -t
啟動/usr/local/nginx/sbin/nginx
平滑重載/usr/local/nginx/sbin/nginx -s reload
平滑停止/usr/local/nginx/sbin/nginx -s quit
強制停止/usr/local/nginx/sbin/nginx -s stop
查看編譯參數/usr/local/nginx/sbin/nginx -V
信號控制(升級)kill -USR2 $(cat /usr/local/nginx/logs/nginx.pid)

最佳實踐建議

  • 配置模組化:主 nginx.conf 僅保留全局設置,站點配置拆分至 vhost/,通用片段用 include 引入
  • 版本控制:/usr/local/nginx/conf/ 整目錄納入 Git 管理
  • 備份機制:修改前 cp nginx.conf nginx.conf.$(date +%F)
  • 日誌輪轉:配置 logrotate 每日切割、保留 30 天、壓縮舊日誌
  • 權限最小化:配置文件 640 root:www,二進制 755 root:root

包管理器安裝路徑差異

發行版/來源配置目錄二進制站點目錄
CentOS/RHEL (yum)/etc/nginx//usr/sbin/nginx/etc/nginx/conf.d/
Ubuntu/Debian (apt)/etc/nginx//usr/sbin/nginx/etc/nginx/sites-enabled/
OpenResty/usr/local/openresty/nginx/conf//usr/local/openresty/nginx/sbin/nginx同源碼編譯
Tengine/etc/tengine//usr/sbin/tengine/etc/tengine/conf.d/

總結

熟悉 Nginx 目錄結構是高效運維的基礎。源碼編譯安裝路徑固定在 /usr/local/nginx,包管理器安裝遵循 FHS 標準落在 /etc/nginx。無論哪種方式,建議統一採用「主配置+虛擬主機分文件+Include 共用片段」的模組化管理模式,配合版本控制與自動化部署,實現配置的可追溯、可回滾、可審計。

Copyright © Windows教程網 All Rights Reserved