nginx 配置

Posted maxwell_xu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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; 

3,ssl配置,https需要配置ssl

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

4,https的socket需要配置转发,如有CDN,域名socket通信需CDN支持支持

   upstream port_10001{ server 123.123.123.123:10001;  }
   location /10001 {proxy_pass http://port_10310; proxy_http_version 1.1;  proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade";}

 

以上是关于nginx 配置的主要内容,如果未能解决你的问题,请参考以下文章

Nginx——Nginx启动报错Job for nginx.service failed because the control process exited with error code(代码片段

Nginx配置文件详细介绍

Nginx 跨域

Nginx的配置

VSCode自定义代码片段11——vue路由的配置

VSCode自定义代码片段11——vue路由的配置