zoukankan      html  css  js  c++  java
  • 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";}
  • 相关阅读:
    python连接SMTP的TLS(587端口)发邮件python发邮件(带认证,587端口)202010
    JAVA抓取通过JS渲染的网站(动态)网页数据
    moviepy音视频剪辑:与大小相关的视频变换函数详解
    区块链知识博文1: 共识算法之争(PBFT,Raft,PoW,PoS,DPoS,Ripple)
    MoviePy v2.0.0.dev1尚不成熟,不建议大家使用
    区块链学习2:一些概念性的基础知识笔记
    老猿学5G:3GPP 5G规范中的URI资源概念
    区块链学习1:Merkle树(默克尔树)和Merkle根
    老猿Python博客文章目录索引
    老猿学5G:融合计费场景的Nchf_ConvergedCharging_Create、Update和Release融合计费消息交互过程
  • 原文地址:https://www.cnblogs.com/maxwell-xu/p/7783727.html
Copyright © 2011-2022 走看看