将vue项目进行打包:
npm run build
在文件夹中会出现一个dist文件夹,这就是打好的包。
在阿里云上下载安装nginx后,在/usr/local文件夹中会有一个nginx文件夹,其中的conf文件夹中的nginx.conf就是nginx的配置文件。
在http模块配置location
location / {
root /root/app/dist/; //指向目标项目的文件夹,
index index.html index.htm;
try_files $uri $uri/ /index.html;
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept' always;
}
location /api/ {
rewrite ^.+api/?(.*)$ /$1 break;//这个很重要
proxy_pass http://xxxxxxxx:3000;//需要的代理到后台的地址以及端口号
proxy_set_header Host $host:$server_port;
}
最后重新启动nginx就行了,nginx目录下
sbin/nginx -s reload