nginx 配置文件

最近在研究nginx ,配置文件做了一些说明,在这里记录一下。
常用命令:start nginx nginx -s reload|reopen|stop|quit #重新加载配置|重启|停止|退出

#设置用户
#user  nobody;
#工作衍生进程数 [最合适的值是CPU核数或者核数2倍]
worker_processes  4;

#设置错误文件存放日志
error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;

#设置pid存放路径(pid是控制系统中重要文件)
#pid        logs/nginx.pid;

#设置最大连接数
events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #负载均衡服务器列表
    upstream myproject {
        #设置ip_hash 这个指令的意思是说用户第一次登录了那个服务器,以后都会登录这个服务器,确保了登录信息不会丢失.
        ip_hash;
        # server 192.168.0.113:9090 weight=2;     weight是权重的意思,默认都是1, 如果某个服务器的权重大,被访问到的概率就大;
        #例如第一个服务器的权重是2 , 第二个服务器的权重是1 那么被访问的概率分别是 2/3  1/3
        server 192.168.0.113:9090;
        server 192.168.0.113:8080;
    }



    #日志文件的格式配置=========================================
    #combined 默认格式
    #remote_addr 客户端IP地址
    #remote_user 客户端的用户名
    #$request 请求的url
    #$status 请求状态
    #$body_bytes_sent  服务器发送给客户端的字节数
    #$http_referer 原网页--用户从哪里访问过来的
    #$http_user_agent 客户端浏览器信息
    #$http_x_forwarded_for 客户端的IP地址
       log_format  log_format1  '$remote_addr - $remote_user  [$time_local]  '
                                   ' "$request"  $status  $body_bytes_sent  '
                                   ' "$http_referer"  "$http_user_agent" ';

       log_format  log_format2  '$remote_addr - $remote_user  [$time_local]  '
       ' "$request"  $status  $body_bytes_sent  '
       ' "$http_referer"  "$http_user_agent" ';

    #不开启日志存储   
    #access_log off;
    #access_log  logs/access.log  log_format1;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #开启gzip压缩 小于1k不进行压缩,
    #大于1k才进行压缩处理
    #申请内存为4个16k的数据流
    #http版本 1.1
    #开启判断客户端是否支持gzip压缩,如果不支持,服务器就不会进行压缩了
    gzip  on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.1;
    gzip_vary on;

    server {
        listen       8888;
        server_name  192.168.0.113;

        #设置字符编码
        charset utf-8;

        access_log  logs/host.access.log  log_format1;

        #location / {
        #    root   html;
        #    index  bry.html;
            #自动列目录
        #   autoindex on;
        #}


        #负载均衡配置 监听根目录 
        #win7强制关闭nginx 进程   taskkill /im QQMusic.exe /f 

        location / {
                proxy_pass http://myproject;
                #禁用缓存 
                proxy_buffering off;
        } 



        #配置缓存
        #location ~.*\.(jpg|png|swf)$ {
           #30天之后自动清除缓存
          # expires 30d;
        #}
        #location ~.*\.(css|js)$ {
           #1小时之后自动清除缓存
          # expires 1h;
        #}

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


    server {
        listen       9999;
        server_name  192.168.0.113;

        #设置字符编码
        charset utf-8;
        access_log  logs/test/access.log  log_format2;

        location / {
            root   html/test;
            index  bry2.html;
        }


    }



}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值