nginx配置檔案預設存放在nginx安裝目錄下的conf目錄下
配置檔案主要分為:全局塊、events塊、http塊、server塊、location塊
[root@localhost conf]# cat nginx.conf
#####全局 開始####
#user nobody nobody; #指定運作nginx伺服器的使用者群組(必須配置在全局中)
worker_processes 1; #配置允許生成的work process程序數,mumber為生成最多,atuo為根據伺服器性能自動檢測(必須配置在全局中)
#error_log logs/error.log; #配置nginx的錯誤日志存放路徑,在全局塊、http塊、server塊中都可配置,級别分為(info、notice、warn、error、crit、alert、emerg)
#error_log logs/error.log notice; 設定某一級别後,比這一級高的日志也會被記錄下來。
#error_log logs/error.log info;
#pid logs/nginx.pid; #指定存放pid的路徑和檔案名,可以使絕對路徑,也可是基于nginx的相對路徑(必須配置在全局中)
#####全局 結束####
####events 開始####
events {
use epoll; #配置時間驅動模型
worker_connections 1024; #配置最大連接配接數
}
####events 結束####
####http塊 開始####
http {
##nginx開啟目錄浏覽##
autoindex on; #開啟目錄浏覽功能
autoindex_exact_size off; #檔案大小從KB顯示
autoindex_localtime on; #顯示檔案修改時間為本地時間
include mime.types; #配置檔案的引入(mime.types用來區分文本和媒體資源)
default_type application/octet-stream; #配置了用于處理前段請求的mime類型
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' #定義服務日至的格式,main為格式字元串定義名字,供access_log調用
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main; #記錄了服務過程中前段請求的日志。(main為指定的日志格式你在log_format中定義)如要取消,可使用access_log off;
sendfile on; #配置允許sendfile方式傳輸檔案 on|off
sendfile_max_chunk 128k; #表示每個worker process每次調用的sendfile傳輸的資料量不能大于128k,設定為0則表示無限制。
#tcp_nopush on;
keepalive_timeout 65; #表示用戶端連接配接逾時時間為65秒,後面可加一個時間,表示為應答逾時時間(keepalive_timeout 65s 120s)
keepalive_requests number; #設定單連接配接請求上線
#gzip on; #開啟gzip壓縮功能
####http的server塊 開始####
server {
listen 80; #配置網絡監聽端口(可以使ip位址、端口等)
server_name localhost; #配置對外虛拟主機的主機名,可以多個名稱并列,使用空格隔開
#charset koi8-r;
#access_log logs/host.access.log main; #http塊中的日志配置,和全局配置中一樣
#http/server的loction中生效
location /html/ {
root /websits; #配置請求的根目錄(上面的配置表示在location接收到請求時,在/websits/html/下找到index.html相應請求)
index index.html index.htm;
}
#error_page 404 /404.html; #設定網站的錯誤頁面
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html; #設定網站的5xx的錯誤頁面
location = /50x.html { #此location配置表示先捕獲“/50x.html”請求,然後将請求定向到root指定的路徑先
root html;
#基于IP配置nginx的通路權限
location / {
allow 192.168.1.1;
allow 192.168.10.1;
deny all;
} #配置允許192.168.1.1和192.168.10.1通路nginx,拒絕其他所有的通路。
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
# root html; #指定php的路徑
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#location ~ /\.ht {
# deny all;
}
####http的server塊 結束####
####https的server塊 開始####
# HTTPS server
#
#server {
# listen 443; #定義https監聽端口
# server_name localhost; #定義服務名
# ssl on; #on表示開啟https的ssl
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key; #建立的密鑰對
# ssl_session_timeout 5m; #請求逾時時間
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / { #定義通路頁面
# root html;
# index index.html index.htm;
# }
#}
####https的server塊 結束####
####http塊 結束####
本文轉自 亮公子 51CTO部落格,原文連結:http://blog.51cto.com/iyull/1864387