فهرست منبع

更新 'nginx.conf'

fanyong 1 ماه پیش
والد
کامیت
6d4c5dfdbb
1فایلهای تغییر یافته به همراه17 افزوده شده و 2 حذف شده
  1. 17 2
      nginx.conf

+ 17 - 2
nginx.conf

@@ -30,10 +30,25 @@ http {
         gzip_vary off;
         gzip_disable "MSIE [1-6]\."; 
 
-        root /usr/share/nginx/app;
+        root /usr/share/nginx/app/dist;
         location / {
+            try_files $uri $uri/ @router; #需要指向下面的@router否则会出现vue的路由在nginx中刷新出现404
             index  index.html index.htm;
-         	alias /usr/share/nginx/app/;
+        }
+        #对应上面的@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;
         }
     }
 }