nginx配置说明

默认配置文件nginx.conf说明:

nginx.conf:
user  root;	#设置使用用户(worker)
worker_processes  1;    #进行增大并发连接数的处理 跟cpu保持一致 八核设置八个

error_log  /var/log/nginx/error.log warn;	#nginx的错误日志
pid        /var/run/nginx.pid;	 #nginx服务启动时候pid


events {	#定义事件相关的属性
    worker_connections  1024;	#一个进程允许处理的最大连接数
}


http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;	# 请求日志

    sendfile        on;	# 开启高效文件传输模式。
    #tcp_nopush     on;	# 防止网络阻塞

    keepalive_timeout  65;	# 长连接超时时间,单位是秒

    #gzip  on;	# 开启gzip压缩输出

    include /etc/nginx/conf.d/*.conf;		# 导入server配置文件
}
server {
        listen 192.168.63.132:8090;
        # 精确匹配 优先级 1 (越小优先级越高)
        location = / {
			return 404;
        }

        # 优先匹配 优先级 2
        location ~ / {
            return 402;
        }

        # 通用匹配 优先级 4
        location / {
            return 401;
        }

        # try_files 对根路劲 / 匹配无效
        location /a {
            try_files $uri $uri/ =401;
        }
        
        # 配合@使用, 如果能找到指定的uri那么就返回相应的内容,否则的话就内部重定向到后端名称为@backup的location
        location /b {
            try_files $uri $uri/ @demo;    
        }

        location @demo {
            return 403;    
        }
        
        #return 跳转 路径斜杠 / 问题, 后面不加/, 访问xxx/c 和 xxx/c/ 都能访问到; 若加/, 必须访问xxx/c/
        location /c {
            return 302 http://www.baidu.com;    
        }
        
        # 访问控制
        location / {
            stub_status on ;                        # 返回nginx的状态
            allow 192.168.8.14;                     # 允许的访问地址
            deny all;                               # 默认禁止所有访问,除了允许的
        }
        
        # 目录列表(下载控制) 
        location /download {
            alias   /etc/nginx;     # 指定查看文件列表路径(绝对路径)
            autoindex on;                  # 开启目录自动索引(允许下载)
            autoindex_exact_size off;   # 默认on,显示文件确切大小(bytes)。off表示显示文件的大概大小(kB/MB/...)
            autoindex_localtime on;     # 默认off,显示的文件时间为GMT时间。on表示显示文件的服务器时间

        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值