【HAVENT原创】nginx 配置

配置一个最简单的站点

    server {
        listen       801;
        server_name  localhost;
        root         C:\website;
    }

 

增加一个静态目录

    server {
        listen       801;
        server_name  localhost;
        root         C:\website;


          location ^~ /static {
              alias   D:\source\static;
          }
    }

 

代理外部接口

    server {
        listen          801;
        server_name     localhost;
        root            C:\website;

        location ^~ /static {
            alias       D:\source\static;
        }

        location ^~ /api {
            proxy_pass  http://demo.my00.com/api/;
        }
    }

 

参考:详细配置参数说明

#定义nginx运行的用户和用户组
#user  nobody;

#nginx进程数,建议设置为等于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;

#进程pid文件
#pid        logs/nginx.pid;

events {
    #事件驱动模型,use [ kqueue | rtsig | epoll | /dev/poll | select | poll ];
    #epoll模型是Linux 2.6以上版本内核中的高性能网络I/O模型,linux建议epoll,如果跑在FreeBSD上面,就用kqueue模型。
    #补充说明:
    #与apache相类,nginx针对不同的操作系统,有不同的事件模型
    #A)标准事件模型
    #Select、poll属于标准事件模型,如果当前系统不存在更有效的方法,nginx会选择select或poll
    #B)高效事件模型
    #Kqueue:使用于FreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0 和 MacOS X.使用双处理器的MacOS X系统使用kqueue可能会造成内核崩溃。
    #Epoll:使用于Linux内核2.6版本及以后的系统。
    #/dev/poll:使用于Solaris 7 11/99+,HP/UX 11.22+ (eventport),IRIX 6.5.15+ 和 Tru64 UNIX 5.1A+。
    #Eventport:使用于Solaris 10。 为了防止出现内核崩溃的问题, 有必要安装安全补丁。
    #use epoll;
 
    #设置网路连接序列化,防止惊群现象发生,默认为on
    accept_mutex on;
    #设置一个进程是否同时接受多个网络连接,默认为off
    multi_accept on;

    #单个进程最大连接数(最大连接数=连接数*进程数),默认为512
    #根据硬件调整,和前面工作进程配合起来用,尽量大,但是别把cpu跑到100%就行。每个进程允许的最多连接数,理论上每台nginx服务器的最大连接数为。
    worker_connections  1024;
}


http {
    #文件扩展名与文件类型映射表
    include       mime.types;
    #默认文件类型,默认为text/plain
    default_type  application/octet-stream;

    #默认编码
    #charset utf-8;

    #自定义格式
    #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;

    #General Options
    #服务器名字的hash表大小
    #保存服务器名字的hash表是由指令server_names_hash_max_size 和server_names_hash_bucket_size所控制的。参数hash bucket size总是等于hash表的大小,并且是一路处理器缓存大小的倍数。在减少了在内存中的存取次数后,使在处理器中加速查找hash表键值成为可能。如果hash bucket size等于一路处理器缓存的大小,那么在查找键的时候,最坏的情况下在内存中查找的次数为2。第一次是确定存储单元的地址,第二次是在存储单元中查找键 值。因此,如果Nginx给出需要增大hash max size 或 hash bucket size的提示,那么首要的是增大前一个参数的大小.
    server_names_hash_bucket_size 128;
    #客户端请求头部的缓冲区大小
    client_header_buffer_size 32k;
    #客户请求头缓冲大小。nginx默认会用client_header_buffer_size这个buffer来读取header值,如果header过大,它会使用large_client_header_buffers来读取
    large_client_header_buffers 4 32k;
    #设定通过nginx上传文件的大小
    client_max_body_size       50m;
    client_body_buffer_size    8m; #256k
    server_tokens off;
    ignore_invalid_headers   on;
    recursive_error_pages    on;
    server_name_in_redirect off;
    #开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。
    #sendfile指令指定 nginx 是否调用sendfile 函数(zero copy 方式)来输出文件,对于普通应用,必须设为on。如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络IO处理速度,降低系统uptime。
    sendfile                 on;
    #每个进程每次调用传输数量不能大于设定的值,默认为0,即不设上限
    #sendfile_max_chunk 100k;
 
    #连接超时时间,默认为75s,可以在http,server,location块
    keepalive_timeout 60;
    #client_body_timeout   3m;
    #client_header_timeout 3m;
    #send_timeout          3m;
     
    #TCP Options
    #此选项允许或禁止使用socke的TCP_CORK的选项,此选项仅在使用sendfile的时候使用
    tcp_nopush  on;
    tcp_nodelay on;
  
    #gzip模块设置
    #开启gzip压缩输出
    gzip on;
    #最小压缩文件大小
    gzip_min_length  1k;
    #压缩缓冲区
    gzip_buffers     4 16k;
    #压缩版本(默认1.1,前端如果是squid2.5请使用1.0)
    gzip_http_version 1.0;
    #压缩等级
    gzip_comp_level 2;
    #gzip_types       text/xml text/plain application/x-javascript text/css application/xml;
    gzip_types        text/plain text/css application/json application/javascript text/xml text/javascript;
    gzip_vary on;
  
    upstream tomcat {
       ip_hash;
       server 127.0.0.1:8080 max_fails=0 weight=1;
    }
    
    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }


    # server {
        # listen       84;
        # 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 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;
    #    }
    #}

}

 

转载于:https://my.oschina.net/u/943746/blog/1829316

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值