# 参考:https://www.likecs.com/ask-1256888.html user root; worker_processes auto; error_log /var/log/nginx/error.log warn; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; sendfile off; access_log off; ## 关闭正常访问日志 keepalive_timeout 3000; server { listen 80; server_name localhost; #access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log error; ## 静态资源代理 location / { gzip on; #开启或关闭gzip on off gzip_disable "msie6"; #不使用gzip IE6 gzip_min_length 100k; #gzip压缩最小文件大小,超出进行压缩(自行调节) gzip_buffers 4 16k; #buffer 不用修改 gzip_comp_level 8; #压缩级别:1-10,数字越大压缩的越好,时间也越长 gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; # 压缩文件类型 # root 根目录,默认nginx镜像的html文件夹,可以指定其他 root /usr/share/nginx/html; index index.html index.htm; # 如果vue-router使用的是history模式,需要设置这个 try_files $uri $uri/ /index.html; } ## 错误页面 error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } }