利用nginx部署vue项目

主要是利用nginx反向代理实现前后端项目分离的部署
以下是nginx的配置文件


worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream; 

    sendfile        on;
    
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;
		
		root "C:/Users/Administrator/Desktop/test";

        location / {
            
			try_files $uri $uri/ @router;
			# 请求指向的首页
			index index.html;
        }
		
		location @router {
			rewrite ^.*$ /index.html last;
		}
		
		location /api {
			proxy_pass http://10.2.2.30:888;
			rewrite ^/api/(.*)$ /$1 break;
			proxy_http_version 1.1;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection ‘upgrade’;
			proxy_set_header Host $host;
			proxy_cache_bypass $http_upgrade;   
		}
        
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        
    }

}

猜你喜欢

转载自blog.csdn.net/qq_41454044/article/details/101368465