浏览代码

Merge branch 'main' of 118.31.50.10:wangxiaodong/fara-fe-h5

王晓东 1 月之前
父节点
当前提交
c7e1e93e18
共有 2 个文件被更改,包括 61 次插入0 次删除
  1. 7 0
      Dockerfile
  2. 54 0
      nginx.conf

+ 7 - 0
Dockerfile

@@ -0,0 +1,7 @@
+FROM registry.us-west-1.aliyuncs.com/wehome-base/nginx
+RUN mkdir /usr/share/nginx/app
+RUN mkdir /usr/share/nginx/app/dist
+RUN rm -rf /etc/nginx/nginx.conf
+COPY ./nginx.conf /etc/nginx/nginx.conf
+COPY ./dist /usr/share/nginx/app/dist
+EXPOSE 10000

+ 54 - 0
nginx.conf

@@ -0,0 +1,54 @@
+worker_processes  4;
+
+events {
+    worker_connections  8192;
+}
+
+
+http {
+    include       mime.types;
+    default_type  application/octet-stream;
+
+
+    sendfile        on;
+
+    keepalive_timeout  65;
+    server {
+        listen 10000;
+        server_name localhost;
+        
+        proxy_set_header Host $host;
+        proxy_set_header X-Real-IP $remote_addr;
+        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+
+        gzip off;
+        gzip_min_length 1k;
+        gzip_buffers 4 16k;
+        #gzip_http_version 1.0;
+        gzip_comp_level 5;
+        gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
+        gzip_vary off;
+        gzip_disable "MSIE [1-6]\."; 
+
+        root /usr/share/nginx/app/dist;
+        location / {
+            try_files $uri $uri/ @router; #需要指向下面的@router否则会出现vue的路由在nginx中刷新出现404
+            index  index.html index.htm;
+        }
+        #对应上面的@router,主要原因是路由的路径资源并不是一个真实的路径,所以无法找到具体的文件
+        #因此需要rewrite到index.html中,然后交给路由在处理请求资源
+        location @router {
+            
+            rewrite ^.*$ /index.html last;
+            
+            add_header Access-Control-Allow-Methods *;
+            add_header Access-Control-Max-Age 3600;
+            add_header Access-Control-Allow-Credentials true;
+            add_header Access-Control-Allow-Origin $http_origin;
+            add_header Cache-Control  max-age=no-cache;
+            add_header Cross-Origin-Embedder-Policy require-corp;
+            add_header Cross-Origin-Opener-Policy same-origin;
+            add_header cross-origin-resource-policy cross-origin;
+        }
+    }
+}