Nginx配置文件

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#打开errror日志
error_log  logs/error.log  debug;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
	#对具体Ip打日志
	debug_connection   192.168.0.123
}


http {
    include       mime.types;
	#禁止Ip,黑名单
	include       ip.black;
    default_type  application/octet-stream;
	#日志配置
    log_format  main  '$host $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        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost  default;
		access_log logs/$host.acess.log main;

        #charset koi8-r; 

        #access_log  logs/host.access.log  main;

       #正则表达,优先级最高
		location ~* \.(gif|jpg|png|css|js)$ {
			root /usr/www/static;
			valid_referers none blocked *.luban.com;
			if ($invalid_referer) {
				return 403;
			}
		}
		
		location /static {
			alias /usr/www/static;
		}
		#优先级最低
		 location / {
            root   /opt/www/xiaodao/;
            index  index.html index.htm; 
        }
		#限速
		location /download {
			#下载最大速度
			limit_rate 1m;
			#下载超过30M后开始限速
			limit_rate_after 30m;	
		}

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


    }



}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Nginx 配置文件是一个文本文件,通常位于 `/etc/nginx/` 目录下,主要包括以下几个部分: 1. 全局块:配置影响 nginx 全局的指令,一般有运行 nginx 的用户组、nginx 进程 pid 存放路径、日志存放路径和类型以及配置文件引入等。 2. events 块: 配置影响 nginx 服务器或与用户的网络连接,常用于设置连接超时时间、最大连接数等。 3. http 块:http 块中定义的配置指令用于处理 Web 请求,主要包括了 MIME 类型、字符集、缓存、请求限制等。 4. server 块:配置虚拟主机的相关参数,一个 http 块中可以包含多个 server 块,每个 server 块就相当于一个虚拟主机,用于处理来自客户端的请求。 一个简单的 Nginx 配置文件示例如下: ``` user nginx; worker_processes auto; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log main; sendfile on; keepalive_timeout 65; server { listen 80; server_name example.com; location / { root /usr/share/nginx/html; index index.html index.htm; } } } ``` 这个配置文件包含全局块和一个 server 块,其中: - `user` 指定 Nginx 运行的用户; - `worker_processes` 指定 Nginx 启动的 worker 进程数; - `error_log` 指定错误日志文件路径和级别; - `pid` 指定 Nginx 进程 ID 存放路径; - `events` 块中 `worker_connections` 指定每个 worker 进程最大连接数; - `http` 块中 `include` 指定 MIME 类型配置文件路径; - `default_type` 指定默认 MIME 类型; - `access_log` 指定访问日志文件路径和格式; - `sendfile` 指定是否使用 sendfile 函数传输文件; - `keepalive_timeout` 指定 keep-alive 连接超时时间; - `server` 块中 `listen` 指定监听端口和协议; - `server_name` 指定虚拟主机域名; - `location` 指定请求 URL 和对应的文件路径。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值