美文网首页
Nginx配置文件

Nginx配置文件

作者: 橄榄树下的托马斯 | 来源:发表于2017-05-28 12:02 被阅读0次

作者:刘宾, thomas_liub@hotmail.com
请尊重作者著作权,转载请注明出处,谢谢!


例子

worker_processes  4;            # 工作进程数量, 建议配置成主机CPU内核数量
error_log logs/error.log debug; # 日志文件和日志级别, debug, info, error,
pid logs/nginx.pid;             # nginx 进程pid文件

events {
    #参考事件模型,use [ kqueue | rtsig | epoll | /dev/poll | select | poll ]; epoll模型是Linux 2.6以上版本内核中的高性能网络I/O模型,如果跑在FreeBSD上面,就用kqueue模型。
    use epoll;
    worker_connections 1024;    # 单工作进程支持最大连接数
}

# 一个nginx进程打开的最多文件描述符数目,理论值应该是最多打开文件数(系统的值ulimit -n)与nginx进程数相除,但是nginx分配请求并不均匀,所以建议与ulimit -n的值保持一致。
# worker_rlimit_nofile 65535;

http {
    include     mime.types;
    default_type application/octet-stream;
    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 函数(zero copy 方式)来输出文件,
    #对于普通应用,必须设为 on,
    #如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,
    #以平衡磁盘与网络I/O处理速度,降低系统的uptime.
    sendfile     on;
    #tcp_nopush     on;
    #tcp_nodelay     on;
    keepalive_timeout  65;

    #开启gzip压缩
    gzip  on;
    gzip_disable "MSIE [1-6].";

    # lua扩展模块包路径
    lua_package_path '$prefix/lua/?.lua;$prefix/lua/lib/?.lua;;';

    # lua cache,开发模式下设为off, 发布模式下设为on
    lua_code_cache off;

    # for open HTTPS connection
    ssl on;
    ssl_certificate /home/xxx/project/resty-gateway/luamod/conf/server.crt;
    ssl_certificate_key /home/xxx/project/resty-gateway/luamod/conf/server.key;

    resolver 192.168.32.21;   # DNS server

    #设定请求缓冲
    client_header_buffer_size    128k;
    large_client_header_buffers  4 128k;

    # 设定负载均衡后台服务器列表
    upstream backend {
    #ip_hash;
    server 192.168.10.100:8080 max_fails=2 fail_timeout=30s ;
    server 192.168.10.101:8080 max_fails=2 fail_timeout=30s ;
    }

    # SSO server
    server {
        listen 8888;
        server_name  localhost;
        
        #定义服务器的默认网站根目录位置
        root html;

        #设定本虚拟主机的访问日志
        access_log  logs/nginx.access.log  main;

        # bypass all to SSO server.
        location / {
            default_type text/html;
            proxy_pass http://192.168.32.28:9090;
        }
    }

    # application server
    server {
        listen 9999;
        server_name  localhost;
       
        root /home/xxx/dnc/mdc/static;

        set $session_storage redis;
        set $session_redis_host 192.168.32.30;

        # url rules
        location /api/dnc {
            # lua extend modules
            access_by_lua_file  lua/sso/access_resty.lua;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass http://192.168.32.30:8090;
        }

        location /api/mdc {
            # lua extend modules
            access_by_lua_file  lua/sso/access_resty.lua;
            proxy_pass http://192.168.32.30:6091;
        }
        
        location /NginxStatus {
            stub_status on;
            access_log on;
            auth_basic "NginxStatus";
            auth_basic_user_file conf/htpasswd;
            #htpasswd文件的内容可以用apache提供的htpasswd工具来产生。
        }

        # 静态文件,nginx自己处理
        location ~ ^/(images|javascript|flash|media|static|php)/ {
            #过期30天,静态文件不怎么更新,过期可以设大一点,如果频繁更新,则可以设置得小一点。
            root /home/xxx/dnc/mdc/;
            expires 10d;
        }
        
        # 静态文件,css/js
        location ~ .*.(js|css)?${ 
            expires 1h; 
        }

        location / {
            default_type text/html;
            access_by_lua_file  lua/sso/access_resty.lua;
            #定义首页索引文件的名称
            index index.php index.html index.htm;
        }

        # 定义错误提示页面
        error_page   500 502 503 504 /50x.html;
        location = /50x.html {
        }

        #禁止访问 .htxxx 文件
            location ~ /.ht {
            deny all;
        }
    }
}

相关文章

  • 第二讲 Nginx模块详解

    本章要点 Nginx 配置文件结构 各个模块的详解 2.1 Nginx配置文件结构 Nginx的配置文件nginx...

  • Nginx配置文件详解

    Nginx配置文件nginx.conf详解 nginx.conf nginx技术一--配置文件nginx.conf...

  • 应用程序常用命令

    nginx: nginx启动:nginx -c nginx配置文件地址检查配置文件是否正确:nginx -t重启n...

  • nginx(五)nginx cmd

    nginx cmd 1、启动nginx start nginx 2、修改配置文件并生效 测试nginx配置文件是否...

  • Nginx配置文件nginx.conf详解和nginx的变量规则

    Nginx配置文件nginx.conf详解 Nginx 总的 配置文件 位置 /usr/local/nginx/c...

  • Nginx使用

    Nginx [toc] nginx命令 参数 Nginx启动 通过指定配置文件启动 配置文件语法检查 Nginx配...

  • nginx配置文件

    nginx配置文件nginx配置文件详解一、nginx配置文件 启动子进程程序默认用户 user nobody;...

  • Nginx 打印body体内容

    Nginx 打印body体内容,修改nginx配置文件nginx.conf 重新加载配置文件 nginx body...

  • nginx(二)

    在修改配置文件后,检查 nginx 配置文件语法是否正确:nginx -t 重新启动 nginx: nginx -...

  • Nginx yum安装目录

    日志切割配置文件/etc/logrotate.d/nginx主要配置文件/etc/nginx/etc/nginx/...

网友评论

      本文标题:Nginx配置文件

      本文链接:https://www.haomeiwen.com/subject/qothfxtx.html