【docker】【openresty】部署vue项目

openresty

nginx和lua的结合体,内置headers-more-nginx-module等nginx的第三方模块。
本文主要用于无缝替代nginx,因为通过dockerfile给nginx增加第三方模块比较复杂。

Dockerfile

/usr/local/openresty/nginx/openresty存放nginx相关的默认路径。

FROM openresty/openresty:1.19.9.1-4-alpine

EXPOSE 80

COPY dist /usr/local/openresty/nginx/html 
COPY nginx.conf /usr/local/openresty/nginx/conf/nginx.conf

ENV TZ=Asia/Shanghai

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

ENTRYPOINT ["nginx"]
CMD ["-g","daemon off;"]

nginx.conf

由于nginx安装的默认路径为/etc/nginx/,一定注意将相关地址改为/usr/local/openresty/nginx/,主要在includeroot

worker_processes  4;

events {
  worker_connections  1024;
}

http {

  sendfile            on;
  tcp_nopush          on;
  tcp_nodelay         on;
  keepalive_timeout   300;
  # types_hash_max_size 2048;
  # client_max_body_size 50m;

  include       /usr/local/openresty/nginx/conf/mime.types;
  default_type  application/octet-stream;

  #以IP为key进行限速,再定义一个共享内存size=10M,name=one,供下面的limit_conn指令使用,共享内存大小能对多少请求进行限速,可以根据业务调整
  # limit_conn_status 589; 
  # limit_conn_zone $binary_remote_addr zone=one:10m;
  # limit_conn_zone $server_name zone=perserver:10m;
  # limit_req_zone $binary_remote_addr zone=allips:100m rate=20r/s;

  gzip on;
  gzip_buffers 32 4K;
  gzip_comp_level 6;
  gzip_min_length 100;
  gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
  gzip_vary on;
  # gzip_disable "MSIE [1-6]\.";

  # include /etc/nginx/conf.d/*.conf;

  server {
    listen       80;
    server_name  _;

    #安全策略
    more_clear_headers 'Server'; #headers-more-nginx-module
    add_header X-Content-Type-Options 'nosniff';
    add_header X-Frame-Options 'DENY';
    add_header X-Xss-Protection '1;mode=block';

    location / {
      root   /usr/local/openresty/nginx/html ;
      try_files $uri /index.html;
    }

    location /intelligenceinsight {
        rewrite ^.+intelligenceinsight/?(.*)$ /nacos-server/$1 break;
        proxy_pass http://gateway:18890; 
        #连接数限制
        # limit_conn one 10;
        # limit_conn perserver 100; 
        #带宽限制,对单个连接限数,如果一个ip两个连接,就是500x2k
        # limit_rate 256k; 
    }

    error_page 404 /404.html;
    location = /404.html {
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    }

  }
}

踩坑事项

  1. 路径错误,沿用yum安装的nginx的默认路径
  2. 按照网上教程修改nginx.conf,注释掉了include mime.types相关内容,导致部署后加载css、js报错MIME 类型 text/plain

你可能感兴趣的:(运维,前端,docker,vue.js,nginx)