NGINX 配置demo

开始一个demo

user  nobody;
worker_processes  8;
worker_rlimit_nofile 65535;
error_log  logs/error.log;
pid        logs/nginx.pid;

events {
    use epoll;
    worker_connections 10240;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format custom   '$remote_addr - $remote_user [$time_local]  '
                    '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agent" $request_time';
    
    sendfile        on;
    tcp_nopush     on;
    keepalive_timeout  0;
    
    gzip  on;
    gzip_min_length 1100;
    gzip_buffers  4 32k;
    gzip_comp_level 9;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/xml text/css;

    upstream demon {
        server  127.0.0.1:3008;
    }

    server {
        listen       80;
        server_name  localhost;

        location /favicon.ico {
            root /srv/demon.nginx.org;
            expires 30d;
            access_log off;
        }

        location /static/ {
            alias /srv/demon.nginx.org/static/;
            expires 30d;
            access_log off;
        }

        location ~* \.(gif|jpg|png)$ { 
            root /srv/demon.nginx.org/images;
        }

        location ~ .*\.(js|css)?$ {
             deny 127.0.0.1;  #拒绝的ip
             allow 127.0.0.2; #允许的ip
             expires 12h;
        }

        location / {
            uwsgi_pass demon;
            include uwsgi_params;
        }

        access_log logs/access_nginx.org.log;
        error_log logs/error_nginx.org.log;
    }
}

一共分为几部分:

  1. 全局 设置 user pid
  2. events 设置网络连接相关
  3. http 包含多个 server
  4. server 设置虚拟主机
  5. location 设置路由

正则规则:

  • 完全匹配 =
  • 大小写敏感 ~
  • 忽略大小写 ~*
  • 前半部分匹配 ^~

特别注意 alias 和 root 的区别 root 指的是根 alias 指的别名

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,092评论 19 139
  • 配置运行Nginx服务器用户(组) 用于配置运行Nginx服务器用户(组)的指令是user,其语法格式为: use...
    吃瓜的东阅读 10,023评论 0 41
  • Nginx简介 解决基于进程模型产生的C10K问题,请求时即使无状态连接如web服务都无法达到并发响应量级一万的现...
    魏镇坪阅读 6,340评论 0 9
  • 1 概述 本文将介绍nginx里http配置段的相关配置,主要介绍ngx_http_core_module这个模块...
    ghbsunny阅读 6,109评论 0 0
  • 基本配置 为了探究nginx的url配置规则,当然需要安装nginx。我使用了vagrant创建了一个虚拟环境的u...
    人世间阅读 15,575评论 7 30

友情链接更多精彩内容