rpm -ql nginx
可查看所有nginx安裝目錄
路徑 | 類型 | 作用 |
---|---|---|
/etc/logrotate.d/nginx | 配置文件 | Nginx 日誌輪轉,用於logrotate服務的日誌切割 |
– | – | – |
/etc/nginx | 目錄、配置文件 | Nginx主配置文件 |
/etc/nginx/nginx.conf | ||
/etc/nginx/conf.d | ||
– | – | – |
/etc/nginx/fastcgi_params | 目錄、配置文件 | Nginx主配置文件 |
/etc/nginx/uwsgi_params | ||
/etc/nginx/scgi_params | ||
– | – | – |
/etc/nginx/koi-utf | 配置文件 | 編碼轉換映射轉化文件 |
/etc/nginx/koi-win | ||
/etc/nginx/win-utf | ||
– | – | – |
/etc/nginx/mime.types | 配置文件 | 設置http協議的Content-type與擴展名對應關係 |
– | – | – |
/usr/lib/systemd/system/nginx-debug.service | 配置文件 | 用於配置出系統守護進程管理器管理方式 |
/usr/lib/systemd/system/nginx.service | ||
/etc/sysconfig/nginx | ||
/etc/sysconfig/nginx-debug | ||
– | – | – |
/usr/lib64/nginx/modules | 目錄 | Nginx模塊目錄 |
/etc/nginx/modules | ||
– | – | – |
/usr/sbin/nginx | 命令 | Nginx服務的啓動管理的終端命令 |
/usr/sbin/nginx-debug | ||
– | – | – |
/usr/share/doc/nginx-1.16.0 | 文件、目錄 | Nginx的手冊和幫助文件 |
/usr/share/doc/nginx-1.16.0/COPYRIGHT | ||
/usr/share/man/man8/nginx.8.gz | ||
– | – | – |
/var/cache/nginx | 目錄 | Nginx的緩存目錄 |
– | – | – |
/var/log/nginx | 目錄 | Nginx的日誌目錄 |
安裝編譯參數
命令:
nginx -V
編譯選項 作用
--prefix=/etc/nginx 安裝目的目錄或路徑
--sbin-path=/usr/sbin/nginx
--modules-path=/usr/lib64/nginx/modules
--conf-path=/etv/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--pid-path=/var/run/nginx.pid
--lock-path=/var/run/nginx.lock
--http-client-body-temp-path=/var/cache/nginx/client_temp 執行對應模塊時,Nginx所保留的臨時性文件
--http-proxy-temp-path=/var/cache/nginx/proxy_temp
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
--http-scgi-temp-path=/var/cache/nginx/scgi_temp
--user=nginx 設定Nginx進程啓動的用戶和組用戶
--group=nginx
--with-cc-opt=parameters 設定額外的參數將被添加到CFLAGS變量
--with-ld-opt=parameters 設置附加的參數,鏈接系統庫
nginx 默認頁面 /usr/share/nginx/html
如果有修改配置文件,可以使用:
//systemctl啓動方式
1.設置開機自啓動
systemctl enable nginx.service
2.啓動nginx服務
systemctl start nginx.service
3.停止開機自啓動
systemctl disable nginx.service
4.查看服務當前狀態
systemctl status nginx.service
5.重新啓動服務
systemctl restart nginx.service , 最好 使用 systemctl reload nginx.service 進行重啓
6.查看所有已啓動的服務
systemctl list-units --type=service
systemctl is-enabled servicename.service #查詢服務是否開機啓動
systemctl enable *.service #開機運行服務
systemctl disable *.service #取消開機運行
systemctl start *.service #啓動服務
systemctl stop *.service #停止服務
systemctl restart *.service #重啓服務
systemctl reload *.service #重新加載服務配置文件
systemctl status *.service #查詢服務運行狀態
systemctl --failed #顯示啓動失敗的服務
*代表某個服務的名字,如http的服務名爲httpd
Nginx 默認配置語法及其含義
1.Nginx.conf 文件
user 設置nginxg服務的系統使用用戶
worker_processes 工作進程數(和CPU核數設置一樣就可以了)
error_log nginx的錯誤日誌
pid nginx服務啓動時候的PID
events 模塊
worker_connections 每個進程允許最大連接數
user 工作進程數
2.Nginx日誌類型
- error_log
- access_log
3.Nginx 變量
HTTP 請求變量 -
- arg_PARAMETER :request請求的對應的參數 http_HEADER
- request請求裏面的header來進行輸出 sent_http_HEADER
- 服務端返回給客戶的response的header,對應的頭信息 進行輸出
內置變量 - Nginx 內置的
自定義變量 - 自己定義
例:
在 nginx.conf 修改log配置,
$remote_addr:表示客戶端的地址
$remote_user :用戶端請求nginx認證的用戶名,不開啓認證模塊,不會記錄
$time_local :nginx的時間
$request :請求行
$status : respons的請求狀態
$body_bytes_sent : 表示服務端響應用戶端的body內的大小
$http_referer:上一級頁面的url記錄
$http_user_agent :http頭信息
$http_x_forwarded_for :頭信息
對應的是請求頭信息裏面的
當你修改了配置文件,可以使用:
nginx -t -c /etc/nginx/nginx.conf
檢查配置是否正確,然後使用:
nginx -s reload -c /etc/nginx/nginx.conf
重新加載配置文件,達到成功修改
執行 curl http://127.0.0.1
命令
這是爲了打印在log 上,測試剛纔是否配置成功,接下來使用命令將日誌打印出來:
tail -n 200 /var/log/nginx/access.log
網上有很多關於log_format的的語法配置,百度一下很多,就不過多描述了
請多多指教!