最近简单熟悉了下nginx的部署,以下是对nginx.conf配置文件的一些注解(注:代码段是nginx.conf的默认内容):
worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { use epoll; worker_connections 1024; }
user:指定Nginx Worker进程运行的用户和组,这里是默认值;
worker_processes:指定nginx启动的进程数,一般设置为和CPU数目一样;
error_log:指定全局的错误日志文件,日志的输出级别可参考Linux系统的日志输出级别;
pid:指定pid的存储文件位置;
events:指定nginx的工作模式和连接数:
· worker_connections:指定单个nginx进程的连接数上限;
· use:指定nginx的工作模式,Linux一般使用epoll,其它还包括select、poll、kqueue、rtsig和/dev/poll。
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 on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { ... } }
include:用以包含其他的配置文件;
default-type:设定默认类型,这里为二进制流;
log_format:指定日志输出的格式;
send-file:指定是否开启高效文件传输模式;
keepalive_timeout:指定连接保持活动的超时时长;
gzip:是否开启gzip压缩
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; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} #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; #} #location ~ /\.ht { # deny all; #} }
listen:指定端口号;
server_name:指定IP地址或域名,多个域名之间用空格隔开;
charset:指定默认的网页编码格式;
access_log:指定访问日志的路径;
location用于指定各URL的处理方式,如:
location / {
root html;
index index.html index.htm;
}
表示默认由nginx处理,root指定根目录的位置,index定义首页索引文件的名称;
又如:
location ~ \.php$ {
proxy_pass http://127.0.0.1:8000;
}
表示把以.php结尾的动态页面交由本地8000端口处理;
又如:
location ~/favicon.ico {
alias /home/www/favicon.ico;
log_not_found off;
expires 30d;
break;
}
表示静态文件的映射,其中expires指定静态文件的过期时间,这里为30天。