当前位置:   article > 正文

uniapp 部署h5,pdf预览

uniapp 部署h5,pdf预览

1.hubuilderx 打包h5。

2.上传部署包到服务器

解压部署包:unzip h5.zip  。

3.nginx配置。

  1. user root;
  2. worker_processes 1;
  3. #worker_cpu_affinity 0001 0010 0100 1000;
  4. #error_log logs/error.log;
  5. #error_log logs/error.log notice;
  6. error_log /var/log/nginx/error.log info;
  7. pid /run/nginx.pid;
  8. events {
  9. use epoll;
  10. worker_connections 65535;
  11. }
  12. http {
  13. include mime.types;
  14. default_type application/octet-stream;
  15. log_format log_access '$remote_addr - $remote_user [$time_local] "$request" $http_host '
  16. '$status $body_bytes_sent "$http_referer" '
  17. '"$http_user_agent" "$http_x_forwarded_for" '
  18. '"$upstream_addr" "$upstream_status" $upstream_cache_status "$upstream_http_content_type" "$upstream_response_time" > $request_time ' ;
  19. server_tokens off;
  20. sendfile on;
  21. tcp_nopush on;
  22. tcp_nodelay on;
  23. client_body_timeout 20;
  24. client_header_timeout 20;
  25. keepalive_timeout 3000;
  26. send_timeout 20;
  27. gzip on;
  28. gzip_min_length 1k;
  29. gzip_buffers 4 16k;
  30. gzip_http_version 1.0;
  31. gzip_comp_level 2;
  32. gzip_types text/plain application/x-javascript text/css application/xml application/javascript application/octet-stream;
  33. gzip_vary on;
  34. server {
  35. listen 9527;
  36. server_name localhost 109.29.219.139;
  37. location /h5 {
  38. alias /home/app/exam/h5/;
  39. index index.html index.htm;
  40. try_files $uri $uri/ /index.html =404;
  41. }
  42. location /static {
  43. root /home/app/exam/h5;
  44. }
  45. error_page 500 502 503 504 /50x.html;
  46. location = /50x.html {
  47. root html;
  48. }
  49. }
  50. }

4.启动docker容器

docker run --name exam_h5_nginx  -p 9527:9527   -d -v /usr/local/nginx/conf/exam_h5_nginx.conf:/etc/nginx/nginx.conf -v /home/app:/home/app nginx

 5.至此已部署完成,访问发现预览pdf时报错。

 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/octet-stream". Strict MIME type checking is enforced for module scripts per HTML spec。

原因为pdfjs中的mjs文件无法识别返回了默认类型"application/octet-stream"。导致无法预览pdf。

6.问题解决。

增加mjs 到javascript类型。

vim /usr/local/nginx/conf/exam_h5_mime.types

  1. types {
  2. text/html html htm shtml;
  3. text/css css;
  4. text/xml xml;
  5. image/gif gif;
  6. image/jpeg jpeg jpg;
  7. application/javascript js mjs;
  8. application/atom+xml atom;
  9. application/rss+xml rss;
  10. text/mathml mml;
  11. text/plain txt;
  12. text/vnd.sun.j2me.app-descriptor jad;
  13. text/vnd.wap.wml wml;
  14. text/x-component htc;
  15. image/avif avif;
  16. image/png png;
  17. image/svg+xml svg svgz;
  18. image/tiff tif tiff;
  19. image/vnd.wap.wbmp wbmp;
  20. image/webp webp;
  21. image/x-icon ico;
  22. image/x-jng jng;
  23. image/x-ms-bmp bmp;
  24. font/woff woff;
  25. font/woff2 woff2;
  26. application/java-archive jar war ear;
  27. application/json json;
  28. application/mac-binhex40 hqx;
  29. application/msword doc;
  30. application/pdf pdf;
  31. application/postscript ps eps ai;
  32. application/rtf rtf;
  33. application/vnd.apple.mpegurl m3u8;
  34. application/vnd.google-earth.kml+xml kml;
  35. application/vnd.google-earth.kmz kmz;
  36. application/vnd.ms-excel xls;
  37. application/vnd.ms-fontobject eot;
  38. application/vnd.ms-powerpoint ppt;
  39. application/vnd.oasis.opendocument.graphics odg;
  40. application/vnd.oasis.opendocument.presentation odp;
  41. application/vnd.oasis.opendocument.spreadsheet ods;
  42. application/vnd.oasis.opendocument.text odt;
  43. application/vnd.openxmlformats-officedocument.presentationml.presentation
  44. pptx;
  45. application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  46. xlsx;
  47. application/vnd.openxmlformats-officedocument.wordprocessingml.document
  48. docx;
  49. application/vnd.wap.wmlc wmlc;
  50. application/wasm wasm;
  51. application/x-7z-compressed 7z;
  52. application/x-cocoa cco;
  53. application/x-java-archive-diff jardiff;
  54. application/x-java-jnlp-file jnlp;
  55. application/x-makeself run;
  56. application/x-perl pl pm;
  57. application/x-pilot prc pdb;
  58. application/x-rar-compressed rar;
  59. application/x-redhat-package-manager rpm;
  60. application/x-sea sea;
  61. application/x-shockwave-flash swf;
  62. application/x-stuffit sit;
  63. application/x-tcl tcl tk;
  64. application/x-x509-ca-cert der pem crt;
  65. application/x-xpinstall xpi;
  66. application/xhtml+xml xhtml;
  67. application/xspf+xml xspf;
  68. application/zip zip;
  69. application/octet-stream bin exe dll;
  70. application/octet-stream deb;
  71. application/octet-stream dmg;
  72. application/octet-stream iso img;
  73. application/octet-stream msi msp msm;
  74. audio/midi mid midi kar;
  75. audio/mpeg mp3;
  76. audio/ogg ogg;
  77. audio/x-m4a m4a;
  78. audio/x-realaudio ra;
  79. video/3gpp 3gpp 3gp;
  80. video/mp2t ts;
  81. video/mp4 mp4;
  82. video/mpeg mpeg mpg;
  83. video/quicktime mov;
  84. video/webm webm;
  85. video/x-flv flv;
  86. video/x-m4v m4v;
  87. video/x-mng mng;
  88. video/x-ms-asf asx asf;
  89. video/x-ms-wmv wmv;
  90. video/x-msvideo avi;
  91. }

7.删除原来的容器重新运行。

docker rm -f exam_h5_nginx 

docker run --name exam_h5_nginx  -p 9527:9527   -d -v /usr/local/nginx/conf/exam_h5_nginx.conf:/etc/nginx/nginx.conf -v /usr/local/nginx/conf/exam_h5_mime.types:/etc/nginx/mime.types -v /home/app:/home/app nginx

8.pdf能正常预览。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/172702
推荐阅读
相关标签
  

闽ICP备14008679号