nginx 动静分离

# 定义Nginx运行的用户 和 用户组 如果对应服务器暴露在外面的话建议使用权限较小的用户 防止被入侵
# user www www;

#Nginx进程数, 建议设置为等于CPU总核心数
worker_processes 8;

#开启全局错误日志类型
error_log /var/log/nginx/error.log info;

#进程文件
pid /var/run/nginx.pid;

#一个Nginx进程打开的最多文件描述数目 建议与ulimit -n一致
#如果面对高并发时 注意修改该值 ulimit -n 还有部分系统参数 而并非这个单独确定
worker_rlimit_nofile 65535;

events{
    #使用epoll模型提高性能
    use epoll;
    #单个进程最大连接数
    worker_connections 65535;
}

http{
    #扩展名与文件类型映射表
    include mime.types;
    #默认类型
    default_type application/octet-stream;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    #日志
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    #gzip 压缩传输
    gzip on;
    gzip_min_length 1k;  #最小1K
    gzip_buffers 16 64K;
    gzip_http_version 1.1;
    gzip_comp_level 6;
    gzip_types text/plain application/x-javascript text/css application/xml application/javascript;
    gzip_vary on;
    #负载均衡组
    #静态服务器组
    upstream static.zh-jieli.com {
        server 127.0.0.1:808 weight=1;
    }
    #动态服务器组
    upstream zh-jieli.com {

        ip_hash;#治标办法,解决session问题,治本:缓存管理
        server 127.0.0.1:8080;
        #server 192.168.8.203:8080;
    }
    #配置代理参数
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    client_max_body_size 10m;
    client_body_buffer_size 128k;
    proxy_connect_timeout 65;
    proxy_send_timeout 65;
    proxy_read_timeout 65;
    proxy_buffer_size 4k;
    proxy_buffers 4 32k;
    proxy_busy_buffers_size 64k;
    #缓存配置
    proxy_cache_key '$host:$server_port$request_uri';
    proxy_temp_file_write_size 64k;
    proxy_temp_path /dev/shm/JieLiERP/proxy_temp_path;
    proxy_cache_path /dev/shm/JieLiERP/proxy_cache_path levels=1:2 keys_zone=cache_one:200m inactive=5d max_size=1g;
    proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;

    server{
        listen 80;
        server_name erp.zh-jieli.com;
        location / {
            index index; #默认主页为 /index
            #proxy_pass http://jieli;
        }
        location ~ .*\.(js|css|ico|png|jpg|eot|svg|ttf|woff) {
            proxy_cache cache_one;
            proxy_cache_valid 200 304 302 5d;
            proxy_cache_valid any 5d;
            proxy_cache_key '$host:$server_port$request_uri';
            add_header X-Cache '$upstream_cache_status from $host';
            proxy_pass http://static.zh-jieli.com;
            #所有静态文件直接读取硬盘
            #           root /var/lib/tomcat7/webapps/JieLiERP/WEB-INF ;
            expires 30d; #缓存30天
        }
        #其他页面反向代理到tomcat容器
        location ~ .*$ {
            index index;
            proxy_pass http://zh-jieli.com;
        }
    }
    server{
        listen 808;
        server_name static;
        location / {

        }
        location ~ .*\.(js|css|ico|png|jpg|eot|svg|ttf|woff) {
            #所有静态文件直接读取硬盘
            root /var/lib/tomcat7/webapps/JieLiERP/WEB-INF ;
            expires 30d; #缓存30天
        }
    }
}

猜你喜欢

转载自blog.csdn.net/xiaogg3678/article/details/82756667
今日推荐