Windows配置Nginx部署vue-cil项目

  1. nginx下载

nginx下载地址

  1. 打包vue-cil项目

cmd中输入以下命令,打包生成dist文件

npm run build
  1. .修改nginx配置文件nginx/conf/nginx.conf
worker_processes  1;

events {
worker_connections 1024;
}


http {

keepalive_timeout 65;

server {
listen 8200;
server_name localhost;


location / {
root html;
index index.html index.htm;
try_files $uri $uri/ @router;
}
location @router {
rewrite ^.*$ /index.html last;
}

location ^~ /api {
proxy_pass http://xx.xx.xxx.xxx:8100;
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 Access-Control-Allow-Headers $http_access_control_request_headers;
if ($request_method = OPTIONS ) {
return 200;
}
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

}
}

  1. 把打包好的dist放入nginx/html文件夹中

  2. CMD启动nginx

start nginx
  1. 访问localhost:8200成功

nginx常用命令

查看帮助信息
nginx -h

查看nginx版本(小写字母v)
nginx -v

除版本信息外还显示配置参数信息(大写字母V)
nginx -V

启动nginx
start nginx

指定配置文件启动nginx
start nginx -c filename

关闭nginx,完整有序的停止nginx,保存相关信息
nginx -s quit

关闭nginx,快速停止nginx,可能并不保存相关信息
nginx -s stop

重新载入nginx,当配置信息修改需要重新加载配置是使用
nginx -s reload

重新打开日志文件
nginx -s reopen

测试nginx配置文件是否正确
nginx -t -c filename