vue项目配置

server {
			listen   8888;
            server_name  localhost;
			root   C:/你的打包目录;   
			index  index.html index.htm;
	location /{
		try_files $uri $uri/ @router;   #重点:必须设置,不然会导致刷新时页面找不到,造成404
		index  index.html index.htm;
	}
	location @router{                   #重点:这里用来进行重写操作, 对应上面的@router
		rewrite ^.*$ /index.html last;
	}
	location ~* \.(css|js)$ {
     	gzip_static on; #可选
  	}
	location ~ ^/api/ {						   #可选: api转发,转发到你的api发布地址
         rewrite ^/api/(.*)$ /$1 break;
         proxy_pass http://127.0.0.1:9999;
   	}
}

Php部署
server {
			listen   9999;
            server_name  localhost;
			root   C:/PHP/phpStudy_64/phpstudy_pro/WWW/api;   
			index  index.php index.html;
		
            #charset koi8-r;
            #access_log  logs/host.access.log  main;
						add_header Access-Control-Allow-Origin *;
			add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
			add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
			if ($request_method = 'OPTIONS') {
				return 204;
		}
		
 		location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
        location / {
				if (!-e $request_filename) {       
  				 rewrite  ^(.*)$  /index.php?s=/$1  last;        break;    
		}
		}
}

Nginx开启gzip配置

在这里插入图片描述

vue方面开启跨域选项,并用api进行转发(仅用于开发环境下)

api地址转发

参考链接: https://www.cnblogs.com/helloluckworld/articles/9517027.html

静态文件地址配置

  server {
   charset gbk,utf-8;
        listen       9991;
        server_name  localhost;
		
        add_header Access-Control-Allow-Origin *;
		location /{
		root E:/xxxxx/staticFile; //物理机目录
		autoindex on;
		autoindex_exact_size off;
		autoindex_localtime on;
		charset gbk,utf-8;
		}
       
    }

qiankun同服务器设置

       server {
        listen       7100;
        server_name  localhost;
	
        location / {
            root E:/nginx_prod/platform/main;
            index  index.html index.htm;
            try_files $uri $uri/ @router;
			
			expires -1;
			add_header Cache-Control no-cache;
           
        }
        location /microApps/checkannot {
            alias E:/nginx_prod/platform/apps_micro/apps_xxxxxx/;
            index  index.html index.htm;
            try_files $uri $uri/ @router;
			
			expires -1;
			add_header Cache-Control no-cache;
        }
		location /microApps/teamwork {
            alias E:/nginx_prod/platform/apps_micro/apps_xxxxxx/;
            index  index.html index.htm;
            try_files $uri $uri/ @router;
			
			expires -1;
			add_header Cache-Control no-cache;
        }
		
		location @router{
			rewrite ^.*$ /index.html last;
		}
		
		location  ^~ \.(css|js)$ {
			gzip_static on;
		}
		
    }
Logo

前往低代码交流专区

更多推荐