一、下载nginx
从网站下载nginx:https://nginx.org/en/download.html
二、编写配置文件
编辑conf文件夹中的nginx.conf文件。
location / {
root M:\vue\Bproject\project-v2\dist;
try_files $uri $uri/ @router;#解决404问题
index index.html index.htm;
error_page 405 =200 $uri;#解决post接口报405问题
}
location @router
{
rewrite ^.*$ /index.html last;
}
#解决访问后台接口返回html页面的问题
location ^~ /api/ {
proxy_pass http://192.168.8.111:80/;
}
三、检查配置文件合法性
在nginx.exe所在目录打开控制台,输入:nginx -t -c C:\Users\Administrator\Downloads\nginx-1.20.2\conf\nginx.conf
显示successful则表示配置文件OK。
注意:nginx.conf文件另存为ANSI编码,否则任何修改都将不成功。
四、启动nginx
start nginx