nginx配置 nginx.conf详解

#定义nginx的用户和用户组,来指定nginx worker进程运行用户以及用户组,默认由nobody账号运行

#user  nobody;

#nginx进程数,建议设置为等于cpu总核心数

worker_processes  1;

#全局错误日志定义类型:【debug、info、notice、warn、error、crit】其中debug输出日志量最详细,crit最少

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

error_log  logs/error.log  info;

#进程文件,用来指定进程ID的存储文件位置

pid       logs/nginx.pid;

#工作模式与连接上限

events {

    #Mac平台用kqueue,对于Linux系统来说epoll工作模式是首选

    #用来定义nginx每个进程的最大连接数,即接收前端的最大请求数,默认是1024,最大客户端连接数由worker_processes和worker_connections决定,即Max_clients=worker_processes*worker_connections,在作为反向代理时,Max_clients = worker_processes * woker_connections /4.进程的最大连接数受Linux系统进程的最大打开文件数限制,在执行操作系统命令“ulimit -n 65536”后worker_connection的设置才能生效

    worker_connections  1024;

}

#设置http服务

http {

    #用来设定文件的mine类型,类型在配置文件目录下的mine.type,来告诉nginx来识别文件类型

    include       mime.types;

    #默认文件类型

    default_type  application/octet-stream;

    #用于设置日志的格式,和记录哪些参数,这里设置为main,刚好用于access_log来记录这种类型

    #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指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为on,如果用来进行下载等应用磁盘io重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度。注意:如果图片显示不正常,把这个改成off;

    sendfile        on;

    #开启目录列表访问,合适下载服务器,默认关闭

    #autoindex on;

   

    #防止网络阻塞

    #tcp_nopush     on;

    #防止网络阻塞

    tcp_nodelay on;

    #长链接超时时间,单位为s(秒)

    #keepalive_timeout  0;

    keepalive_timeout  65;

    #FastCGI相关参数是为了改善网站的性能:减少资源占用,提高访问速度。下面参数看字面意思都能理解。

    fastcgi_connect_timeout 300;

    fastcgi_send_timeout 300;

    fastcgi_read_timeout 300;

    fastcgi_buffer_size 64k;

    fastcgi_buffers 4 64k;

    fastcgi_busy_buffers_size 128k;

    fastcgi_temp_file_write_size 128k;

    #开启gzip压缩输出

    #gzip  on;

    #gzip_min_length 1k; #最小压缩文件大小

    #gzip_buffers 4 16k; #压缩缓冲区

    #gzip_http_version 1.0; #压缩版本(默认1.1,前端如果是squid2.5请使用1.0)

    #gzip_comp_level 2; #压缩等级

    #gzip_types text/plain application/x-javascript text/css application/xml;

    #压缩类型,默认就已经包含text/html,所以下面就不用再写了,写上去也不会有问题,但是会有一个warn。

    #gzip_vary on;

    #limit_zone crawler $binary_remote_addr 10m; #开启限制IP连接数的时候需要使用

    #upstream blog.ha97.com {

    #upstream的负载均衡,weight是权重,可以根据机器配置定义权重。weigth参数表示权值,权值越高被分配到的几率越大。

        #server 192.168.80.121:80 weight=3;

        #server 192.168.80.122:80 weight=2;

        #server 192.168.80.123:80 weight=3;

    #}

    #虚拟主机的配置

    server {

        #监听端口

        listen       80; 

        #域名可以有多个用空格隔开www.888.com www.666.com

        server_name  localhost; 

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

            root   html;

            index  index.html index.htm index.php;

        }

        #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配置,让nginx识别PHP

        location ~ \.php$ {

            root           html;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

    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;

        #}

    }

    # 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 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;

    #    }

    #}

    include servers/*;

}

猜你喜欢

转载自blog.csdn.net/hechenhongbo/article/details/105645649