Linux

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > Linux > nginx部署前端项目

用nginx部署前端项目全过程

作者:乌托邦钢铁侠

文章介绍了如何在服务器上部署前端项目,包括将打包好的dist文件夹放在指定路径、安装和配置Nginx、修改配置文件并重新启动Nginx等步骤

1.前端的默认首页使用 index.html

在部署的时候会用到该页面。

2.将打包好的前端页面dist文件夹

放在服务器(centos 或 ubuntu) 指定路径 ,

如 /home/project/shopping, 项目包含js,css和html等

3.安装nginx

sudo su root
apt-get install nginx

查看nginx是否安装成功:

nginx -v

nginx安装成功后的位置如下:

4.修改配置

将项目的根目录所在路径作为 location / 的 root 对应的值, index.html页面作为index 的值

如下配置:

#user  nobody;
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    #tcp_nopush     on;

    #gzip  on;

    server {
        listen       8080;
        server_name  localhost;

        location / {
            root   /home/project/shoping;
            index  index.html index.htm;
        }

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

5.修改完毕后

保证配置无误,重新启动nginx , 可用nginx -t 检验nginx配置是否正确 , 配置无误后

使用 nginx -s reload 命令重新加载修改的配置。

nginx -t 
nginx -s reload
service nginx restart

启动成功后,访问: http://116.62.146.90:8080/, 此处要修改为自己机器的ip地址。

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文