nginx 配置文件解析(一)

nginx.conf

user              nginx; 
    # nginx服务的运行用户
worker_processes  1;
    # 启动进程数,通常设置成和CPU的数量相等

error_log  /var/log/nginx/error.log;
    # 错误日志,错误级别
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;
    
pid        /var/run/nginx.pid;
    # pid文件路径

events {
    worker_connections  1024;
}
    # 工作模式及连接数上限
        详情见 events详解


http {
    # 设定http服务器, 详情见http详解
    include       /etc/nginx/mime.types;
        # 设定 mime类型,类型由mime.type文件定义
    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  /var/log/nginx/access.log  main;
        # 访问日志,级别
    sendfile        on;
        # sendfile 指令指定了nginx 是否调用 sendfile函数(zero copy 方式) 来输出文件,
        # 对于普通应用,必须设置为on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的uptime
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
        # 超时时间
    #gzip  on;
        # 启用压缩
    # Load config files from the /etc/nginx/conf.d directory
    # The default server is in conf.d/default.conf
    include /etc/nginx/conf.d/*.conf;
        # 调用其它位置配置文件.
}

default.conf

server {
    # 服务配置项,具体查询server详解
    listen       80 default_server;
        # 监听端口
    server_name  _;
        # 服务名字.
    #charset koi8-r;
        # 字符集
    #access_log  logs/host.access.log  main;
        # 服务自定义的访问日志
    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;
        # 导入其他位置的配置文件
    location / {
        # 根配置
        root   /usr/share/nginx/html;
            # 根目录的位置
        index  index.html index.htm;
            # 首页直接打开的文件名称从左到右依次搜索
    }

    error_page  404              /404.html;
        # 定义错误提示页面
    location = /404.html {
        root   /usr/share/nginx/html;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/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$ {
        # php 文件的配置,fastcgi配置
         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;
    #}
}

 

posted on 2015-06-30 17:50  Mo-_-!  阅读(376)  评论(0)    收藏  举报

导航