Nginx部署前端应用

Nginx 部署前端应用挺普遍的,本文为演示快速启动项目,其它配置后续再添加。使用的版本windows-1.17.10, linux-1.16.1

1. windows下的nginx配置

修改conf目录下的nginx.conf

server{
   listen 8081;
   server_name localhost;

   location / {
     root /home/tuhuan/apps/build; //你的dist路径
     index index.html index.htm;
   }

   error_page 500 502 503 504 /50x.html;
   location = /50x.html{
     root html;
   }
 }
2. linux下的nginx配置

进入cd /etc/nginx/conf.d 目录, 添加一个自己项目的配置

cd /etc/nginx/conf.d
sudo vim test-8081.conf

把以下内容复制进去并保存

server{
   listen 8081;
   server_name localhost;

   location / {
     root /home/tuhuan/apps/build; //你的dist路径
     index index.html index.htm;
   }

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

linux下的启动和暂停命令

停止服务: service nginx stop
启动服务: service nginx restart

参考文章 : windows下nginx的安装及使用

你可能感兴趣的:(Nginx部署前端应用)