当前位置:   article > 正文

Nginx部署vue项目配置_vue nginx配置

vue nginx配置

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;    
		}
		}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52

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;
		}
       
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

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;
		}
		
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/496240
推荐阅读
相关标签
  

闽ICP备14008679号