nginx多虚拟机 gzip压缩 基本配置

load_module modules/ngx_stream_module.so;   #动态加载模块,必须写道开头
user  nginx;   #使用useradd nginx    添加一个nginx用户
worker_processes  4;   #cpu核心数 * 2
worker_rlimit_nofile   102400;  #配置nginx打开最大文件数  (每个工作进程绑定一个cpu,worker_cpu_affinity配置)
worker_cpu_affinity 0001 0010 0100 1000;  #工作进程使用哪个cpu的核心 (以四核为例)  0001是4核的第一个核心 0010是4核的第二个核心 

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
error_log  logs/error.log  info;

pid        logs/nginx.pid;


events {
    use epoll;
    worker_connections  10240;
}


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;   #在server虚拟目录里面配置日志,这里是全局日志

    sendfile        on;   
    #tcp_nopush     on;

    

    server_tokens off;  #错误的时候关闭输出版本号


    #keepalive_timeout  0;
    keepalive_timeout  30;

    gzip  on;   #压缩会占用cpu
    gzip_buffers 4 16k;
    gzip_comp_level 3;  #压缩等级
    gzip_disable "MSIE[1-6]";   #ie浏览器1-6禁用gzip
    gzip_min_length 1k;
    gzip_http_version 1.0;
    gzip_types text/plaion application/html application/css application/js;  #可以压缩的文件类型
    gzip_vary on;  #根据http头判断是否支持压缩

    client_max_body_size 8m;   #默认允许客户端最大上传文件大小
	
	
	#多虚拟主机
	server{      #当没有匹配一个合适的虚拟主机时,返回这个
		listen 80 default_server;
		server_name _;  #_是随便写的没有意义
		return 444;   #返回444错误,没有意义的,自己知道就好
		
	}
	
	
	server { 
		listen 80;
		server_name nextdevops.com www.nextdevops.com;
		access_log logs/nextdevops.com.access.log main;  #配置日志输出格式及目录
		location / {
			root html/cn;
			index index.html index.htm;
		}
	}
	
	server { 
		listen 80;
		server_name nextdevops.net www.nextdevops.net;
		access_log logs/nextdevops.net.access.log main;  #配置日志输出格式及目录
		location / {
			root html/net;
			index index.html index.htm;
		}
	}

    server {
        listen       80;
        #server_name  nextdevops.cn www.netdevips.cn;
        server_name localhost;
        charset utf-8;

        access_log  logs/nextdevops.cn.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page  404              /404.html;
        location =./404.html{
            root html;  #在html目录建立一个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;
        }
		
		#查看服务器状态
		location /ngx_status{
			stub_status;
			access_log off;  #关闭日志输出
			
		}
		
		
        location ~ \.(jpg|png|gif){
            expires 30d;   #缓存多久,过期时间   30d->30天
        }
		
        location ~ \.(html|css|js){
            expires 1d;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

文章来源: nginx多虚拟机 gzip压缩 基本配置

人吐槽 人点赞

猜你喜欢

发表评论

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:nginx多虚拟机 gzip压缩 基本配置