nginx的参数简单解释

nginx的配置文件主要分为六个区域:main(全局设置), events(工作模式), http(http设置), sever(主机设置), localtal(url匹配).
它们的关系是下层继承上层,如果上层的配置与上层出现冲突,那么下层的会覆盖上层的配置内容



-----全局设置-----
user  nginx;  #运行nginx的用户与用户组
worker_processes  2;    #表示nginx工作进程启动数量,一般修改为CPU的核心数.

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;     #PID文件路径


-----工作模式-----
events {
    worker_connections  1024;   #工作进程中的最大连接数量
}

# load modules compiled as Dynamic Shared Object (DSO)
#
#dso {
#    load ngx_http_fastcgi_module.so;
#    load ngx_http_rewrite_module.so;
#}


-----http设置-----
http {
    include       mime.types;   #引用mime.types文件内容
    default_type  application/octet-stream;     #当文件类型未指定时,默认类型为二进制流.例如没有配置php环境时,nginx不能自动解析,会自动进程下载

    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  70;  #长连接超时时间.0为不启用长连接

    #gzip  on;
    include                    vhost/*.conf;    #引用vhost目录下以.conf结尾的配置文件


-----主机设置-----
    server {
        listen       80;    #监听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;
#   server_name www.holacamisetas.com;
#   
#   ### SSL log Files ##
#   access_log  logs/ssl-access.log;
#   error_log   logs/ssl-error.log;
#
#        ssl                  on;
#        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;
#   index index.html index.htm index.php default.html default.htm default.php;
#                root /home/mgt_esqy01/wwwroot/magento/;
#
#                location / {
#                        try_files $uri @apache;
#                        }
#
#                location @apache {
#                        internal;
#                        proxy_pass https://127.0.0.1:440;
#                        include proxy.conf;
#                        }
#
#                location ~ .*\.(php|php5)?$
#                        {
#                                proxy_pass https://127.0.0.1:440;
#                                include proxy.conf;
#                        }
#
#                location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
#                        {
#                                expires      30d;
#                        }
#
#                location ~ .*\.(js|css)?$
#                        {
#                                expires      12h;
#                        }
#                location /skin/frontend/default/sm_sport/js {
#                        concat on;
#                }
#    }


}

上面是默认的配置内容,后面再单独更新一篇url的匹配区域的规则

文章来源: nginx的参数简单解释

人吐槽 人点赞

猜你喜欢

发表评论

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:nginx的参数简单解释