用nginx部署前端项目

用nginx部署前端项目前端的默认首页使用 index html 在部署的时候会用到该页面 将打包好的前端页面放在服务器 centos 或 ubuntu 指定路径 如 home project shopping 项目包含 js css 和 html 等 ubuntu 安装 nginxsudosur getinstallng 查看 nginx 是否安装成功 nginx vnginx 安装成功后的位置如下 usr sbin nginx 主程序 etc 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 

在这里插入图片描述

  1. 修改配置,将项目的根目录所在路径作为 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; } } } 
  1. 修改完毕后,保证配置无误,重新启动nginx , 可用nginx -t 检验nginx配置是否正确 , 配置无误后,使用 nginx -s reload 命令重新加载修改的配置。
nginx -t nginx -s reload service nginx restart 

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

在这里插入图片描述
完结,撒花~

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/208603.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月19日 上午11:11
下一篇 2026年3月19日 上午11:12


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号