(二)Nginx配置文件详解

(二)Nginx配置文件详解


上一章讲到Nginx我安装的是1.14.2版本,我直接拷贝的/usr/local/nginx/conf/nginx.conf。

//全局配置模块

//配置用户或者组,默认为user nobody
#user  nobody;

//允许生成的进程数,默认是1,建议值为服务器CPU核心数。
worker_processes  1;

//错误日志存放文件,日志级别按照从轻到重如下:
//debug | info | notice | warn | error | crit | alert | emerg
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

//Nginx进程文件存放地址
#pid        logs/nginx.pid;


events {
//每个进程允许的最多连接数, 理论上每台nginx 服务器的最大连接数为worker_processes*worker_connections。可以设置为65535
    worker_connections  1024;
}


http {
//文件扩展名与文件类型映射表,文件地址:/usr/local/nginx/conf/mime.types

    include       mime.types;
//默认文件类型。这个选项和上边的一块看,mime.types指定了文件扩展名和文件类型的映射,也就是服务器会根据这个映射表来判断请求的文件是应该被打开还是下载,如果映射表中没有该扩展名则按照默认的方式展现。默认为下载。
    default_type  application/octet-stream;
    
//设置日志格式详细可查看:http://www.cnblogs.com/kevingrace/p/5893499.html
    #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方式传输文件
    sendfile        on;
    
//tcp_nopush配置与tcp_nodelay“互斥”。它可以配置一次发送数据包的大小。也就是说,数据包累积到一定大小后就发送。必须在sendfile开启时才有效。
    #tcp_nopush     on;

//连接超时时间
    #keepalive_timeout  0;
    keepalive_timeout  65;
    
//是否启用gzip压缩
    #gzip  on;

//一个http中可以有多个server监听不同端口提供服务。
    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;
        }

//将PHP文件请求代理到Apache
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
//将PHP文件请求代理到FastCGI server
        # 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;
        #}
//拒绝访问htaccess 
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

//可以开启另外一个server监听不同端口来提供服务。
    # 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服务
    # 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;
    #    }
    #}

}

猜你喜欢

转载自blog.csdn.net/Super_RD/article/details/85171652
今日推荐