Nginx配置文件位于nginx目录下的conf文件夹下,为nginx.conf,下面简单介绍下配置文件中各项的含义,一入nginx深似海,功能非常强大,同时也非常复杂。
全局配置:
user nobody; #运行用户
worker_processes 1; #表示工作进程的数量,通常设置成和CPU的数量相等
全局错误日志以及pid文件
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
Events模块:
events {
worker_connections 1024; #单个后台worker process进程的最大并发连接数
}
http模块:
http {
include mime.types; #设定mime类型,类型由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; #指令指定nginx是否调用sendfile函数来输出文件
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65; #连接超时时间
#gzip on; #开启gzip压缩
autoindex on; #设置显示项目目录
#设定虚拟主机配置
server {
listen 80; #监听80端口
server_name demo.shop.cn; #设置访问域名
root html; #定义服务器的默认项目根目录
#charset koi8-r;
#access_log logs/host.access.log main; #设定本虚拟主机的默认访问日志
#默认请求
location / {
root html;
index index.php 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
#PHP脚本请求全部转发到FastCGI处理,使用FastCGI默认配置
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$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;
#}
}