Site Overlay

Nginx配置文件(nginx.conf)配置详解

仅做参考

user  root;
#Nginx用户及组:用户 组。window下不指定
worker_processes  1;
#工作进程:数目。根据硬件调整,通常等于CPU数量或者2倍于CPU。

error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;
#错误日志:存放路径。

pid        logs/nginx.pid;
#pid(进程标识符):存放路径。


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

    open_file_cache_valid 80s;
    #这个是指多长时间检查一次缓存的有效信息。

    keepalive_timeout 60;
    #连接超时时间。
}


#设定http服务器,利用它的反向代理功能提供负载均衡支持
http {
    include       mime.types;
    #设定mime类型,类型由mime.type文件定义
    default_type  application/octet-stream;
		client_max_body_size 20m; 
    #这个类型会让浏览器认为响应是普通的文件流,并提示用户下载文件。可以通过在Nginx的配置文件中做如下配置达到这样的目的。

    sendfile        on;
    #sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,
    #对于普通应用,必须设为 on,
    #如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,
    #以平衡磁盘与网络I/O处理速度,降低系统的uptime.


    keepalive_timeout  65;
    #连接超时时间。

    limit_conn_zone $server_name zone=mylimitzone:10m;
    #指令描述会话状态存储区域。
    #会话的数目按照指定的变量来决定,它依赖于使用的变量大小和memory_max_size的值。
    server_tokens off;  
    #隐藏版本号。
    

    	
    rewrite_log on;
    # 开启重写日志
    log_format  main escape=json  
    #日志格式定义
    'remote_addr -$remote_addr : $remote_user $server_name [$time_local] "$request" '
    '$status $body_bytes_sent "$request_body" "$http_referer" '
		'"$http_user_agent" "$http_x_forwarded_for" '
		'"Content-Type=$http_content_type" "heard_host0=$host"  "heard_host1=$http_host"' '"HTTP_X_FORWARDED_FOR=$HTTP_X_FORWARDED_FOR"'
		'""';

    server {
				listen       8096;
				server_name  localhost;

				location / {
					alias /root/syncFiles/mbank/app;
					limit_conn mylimitzone 10;
					limit_rate 1024k;
	      }     
                   
    }
    
		server {
        listen       8097;
        server_name  localhost;
				
		location / {
	  access_log logs/mbankStatic.log main;
          alias /root/syncFiles/mbank/app/;
          limit_conn mylimitzone 10;
          limit_rate 1024k;
      	}   
      	


	  #手机端接口调用
		location /mbankAPI/ {
	  #自定义日志文件
	  access_log logs/mabankAPI.log main;
          proxy_pass   http://172.17.54.47:8888/;
          index  index.html index.htm;
				}
      
    }
    
    server {
        listen       8098;
        server_name  localhost;

        location / {
          root   html;
          index  index.html index.htm;
        }
				location /syncFiles {
					alias /root/syncFiles;
					limit_conn mylimitzone 10;
					limit_rate 1024k;
				}  	 
    }
    
    server {
        listen       8099;
        server_name  localhost;

        #gzip配置
        #开启Nginx Gzip压缩
        gzip on;
        #只有超过100k的文件才压缩
        gzip_min_length 100k;
        #image/jpeg类似的图片文件本身就已经时经过压缩的文件,gzip对于文本文件的效果极好
        gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php;
        #低版本IE禁用Gzip压缩
        gzip_disable "MSIE[1-6]\.";
        #压缩使用的缓存,每个内存页为4k,申请32倍
        gzip_buffers 32 4k;
        #设置压缩级别1-9,越大压缩比例越高,但浪费的CPU资源也越多,建议1-4即可
        gzip_comp_level 6;
        gzip_vary on;
        gzip_http_version 1.0;


				location /eeeeeeee {            
					alias /home/fffffffffffffff/;            
					limit_conn mylimitzone 10;     
					limit_rate 1024k;        
				}
				
				location /aaaaaaa {            
						alias /root/eeeeeeeeeeeee;            
						limit_conn mylimitzone 10;        
						limit_rate 1024k;        
					}
    }
    
}

发表回复

您的电子邮箱地址不会被公开。

A beliving heart is your magic My heart
欢迎来到Diuut的个人博客,这里是我的一些零零碎碎的知识汇总,希望有能帮到你的内容。 | 蜀ICP备2021011635号-1 | Copyright © 2024 Diuut. All Rights Reserved.