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的安装及使用

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容