• nginx 配置


    1,添加gzip压缩,在nginx.conf中添加,gzip_types可以在mime.types对应配置

        gzip on;
        gzip_min_length 1k;
        gzip_buffers 4 16k;
        gzip_http_version 1.0;
        gzip_comp_level 1;
        gzip_types    text/css text/plain image/jpeg image/png image/x-icon application/json application/javascript audio/mpeg;
        gzip_vary on;
        gzip_static on;
        gzip_disable "MSIE [1-6].";

    2,添加跨域,egret的话需要在主文件Main.js中添加 egret.ImageLoader.crossOrigin = "anonymous";

    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Headers X-Requested-With;
    add_header Access-Control-Allow-Methods GET,POST,OPTIONS; 

    完整nginx.conf配置

    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  0;
        keepalive_timeout  65;
    
        gzip on;
        gzip_min_length 1k;
        gzip_buffers 4 16k;
        gzip_http_version 1.0;
        gzip_comp_level 1;
        gzip_types    text/css text/plain image/jpeg image/png image/x-icon application/json application/javascript audio/mpeg;
        gzip_vary on;
        gzip_static on;
        gzip_disable "MSIE [1-6].";
        
        # Load config files from the /etc/nginx/conf.d directory
        # The default server is in conf.d/default.conf
        include /etc/nginx/conf.d/default.conf;
    include
    /etc/nginx/conf.d/upstream.conf; #配置转发用
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Headers X-Requested-With;
        add_header Access-Control-Allow-Methods GET,POST,OPTIONS;   
    }

    3,ssl配置,https需要配置ssl,在default.conf中配置

    server { 
       listen 80; listen 443 ssl; server_name 你的域名 ssl_certificate 你的crt路径 ssl_certificate_key 你的key路径; ssl_session_timeout 5m; ssl_session_cache shared:SSL:50m; ssl_protocols SSLv3 SSLv2 TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; underscores_in_headers on; location / { root 你的主目录; index index.html index.htm; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }
    include /etc/nginx/conf.d/location.conf; #https中的socket转发用
    }
    4,https的socket需要配置转发,如有CDN,域名socket通信需CDN支持支持
    在conf.d中添加两个文件
    upstream.conf和location.conf,分别在nginx.conf和default.conf中加载
    upstream.conf中添加
    upstream port_10001{ server 123.123.123.123:10001;  }
    location.conf中添加
    location /10001 {proxy_pass http://port_10001; proxy_http_version 1.1;  proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade";}
  • 相关阅读:
    inner join(inner可省) 与 left join 之间的区别
    Jedis+Redis+spring缓存
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    js中的blob,图片base64URL,file之间的关系
    批量压缩图片
    xhr 的 onpregress 监听上传数据的 已上传 和 总大小
    如何禁止浏览器 前进功能
    获取页面滚动高度
    bootstrap的字体设置
    忽略 文件夹下的所有node/modules
  • 原文地址:https://www.cnblogs.com/maxwell-xu/p/7783727.html
Copyright © 2020-2023  润新知