nginx學習i筆記:

一:命令

nginx -s stop :快速關閉Nginx,可能不保存相關信息,並迅速終止web服務。
nginx -s quit :平穩關閉Nginx,保存相關信息,有安排的結束web服務。
nginx -s reload :因改變了Nginx相關配置,需要重新加載配置而重載。
nginx -s reopen :重新打開日誌文件。
nginx -c filename :爲 Nginx 指定一個配置文件,來代替缺省的。
nginx -t :不運行,而僅僅測試配置文件。nginx 將檢查配置文件的語法的正確性,並嘗試打開配置文件中所引用到的文件。
nginx -v:顯示 nginx 的版本。
nginx -V:顯示 nginx 的版本,編譯器版本和配置參數。

window創建bat文件(rem 爲註釋)

@echo off
rem 如果啓動前已經啓動nginx並記錄下pid文件,會kill指定進程
rem start nginx.exe
nginx.exe -s stop

rem 測試配置文件語法正確性
rem nginx.exe -t -c conf/nginx.conf

rem 顯示版本信息
rem nginx.exe -v

rem 按照指定配置去啓動nginx
rem nginx.exe -c conf/nginx.conf

 二、配置

#運行用戶
#user somebody;

#啓動進程,通常設置成和cpu的數量相等
worker_processes  1;

#全局錯誤日誌
error_log  logs/error.log;
error_log  logs/notice.log  notice;
error_log  logs/info.log  info;

#PID文件,記錄當前啓動的nginx的進程ID
pid        logs/nginx.pid;

#工作模式及連接數上限
events {
   worker_connections 1024;    #單個後臺worker process進程的最大併發鏈接數
}

#設定http服務器,利用它的反向代理功能提供負載均衡支持
http {
   #設定mime類型(郵件支持類型),類型由mime.types文件定義
   include       mime.types;
   default_type  application/octet-stream;
   
   #設定日誌
   log_format  main  '[$remote_addr] - [$remote_user] [$time_local] "$request" '
                     '$status $body_bytes_sent "$http_referer" '
                     '"$http_user_agent" "$http_x_forwarded_for"';
                     
   access_log    logs/access.log main;
   
   #sendfile 指令指定 nginx 是否調用 sendfile 函數(zero copy 方式)來輸出文件,對於普通應用,
   #必須設爲 on,如果用來進行下載等應用磁盤IO重負載應用,可設置爲 off,以平衡磁盤與網絡I/O處理速度,降低系統的uptime.
   sendfile        on;
   #tcp_nopush     on;

   #連接超時時間
   keepalive_timeout  120;
   
   #gzip壓縮開關
   #gzip  on;

   #設定實際的服務器列表 
   upstream zp_server1{
       server 127.0.0.1:8089;
   }

   #HTTP服務器
   server {
       #監聽80端口,80端口是知名端口號,用於HTTP協議
       listen       80;
       
       #定義使用www.xx.com訪問
       server_name  www.hello.com;
       
       #首頁
       index index.html
       
       #指向webapp的目錄
       root D:_WorkspaceProjectgithubzpSpringNotesspring-securityspring-shirosrcmainwebapp;
       
       #編碼格式
       charset utf-8;
       
       #代理配置參數
       proxy_connect_timeout 180;
       proxy_send_timeout 180;
       proxy_read_timeout 180;
       proxy_set_header Host $host;
       proxy_set_header X-Forwarder-For $remote_addr;

       #反向代理的路徑(和upstream綁定),location 後面設置映射的路徑
       location / {
           proxy_pass http://zp_server1;
       } 

       #靜態文件,nginx自己處理
       location ~ ^/(images|javascript|js|css|flash|media|static)/ {
           root D:_WorkspaceProjectgithubzpSpringNotesspring-securityspring-shirosrcmainwebappiews;
           #過期30天,靜態文件不怎麼更新,過期可以設大一點,如果頻繁更新,則可以設置得小一點。
           expires 30d;
       }
   
       #設定查看Nginx狀態的地址
       location /NginxStatus {
           stub_status           on;
           access_log            on;
           auth_basic            "NginxStatus";
           auth_basic_user_file  conf/htpasswd;
       }
   
       #禁止訪問 .htxxx 文件
       location ~ /.ht {
           deny all;
       }
       
       #錯誤處理頁面(可選擇性配置)
       #error_page   404              /404.html;
       #error_page   500 502 503 504  /50x.html;
       #location = /50x.html {
       #    root   html;
       #}
   }
}

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章