#使用的用戶名和組
#user nobody;
#指定工作衍生的進程數(一般是CPU的總核數或者是核數的2倍)
worker_processes 1;
#錯誤日誌存放路徑,錯誤日誌級別{debug | info | notice | warn | error | crit}
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#指定pid存放路徑
#pid logs/nginx.pid;
#指定文件描述符號數量
worker_rlimit_nofile 51200;
events {
#使用的網絡IO模型,Linux系統推薦使用epoll模型,FreeBSD系統推薦使用kqueue模型
use epoll;
#允許的連接數量
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#設置使用的字符集,如果一個網站有多種字符集,請別隨便設置,應該在HTML代碼中通過Meta標籤設置
#charset gb2312;
#日誌格式
#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 on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#設置客戶端能夠上傳的文件大小
client_max_body_size 8m;
#開啓gzip 壓縮
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root 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;
location = /50x.html {
root html;
}
# 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
#
#location ~ \.php$ {
# root html;
# 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;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
log_format指令用來設置日誌的記錄格式,語法如下:
log_format name format [format …]
系統默認的無需設置的combined日誌格式設置,具體參數如下
log_format combined ‘
‘”
另外log_format指令設置的name名稱在Nginx配置文件中是不能重複的。
假設將Nginx服務器作爲Web服務器,位於負載均衡設置、Squid、Nginx反向代理之後,那麼就不能獲取客戶端準確的IP了。因爲經過反向代理之後,由於在客戶端和Web服務器之間增加了中間層,因此Web服務器無法直接拿到客戶端的IP,通過
在日誌格式樣式中,變量
$http_user_agent 用於記錄客戶端瀏覽器信息
用access_log指令指定日誌文件存放路徑
access_log path [format [buffer=size | off]]
path 代表日誌文件的存放路徑,format表示使用log_format指令設置的日誌格式名稱,buffer=size標識設置內存緩衝的大小,例如buffer=32k;
若不想記錄日誌,則可以關閉
access_log off;