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";}