Nginx 搭建静态网站

155 阅读1分钟

极简的搭建步骤

准备服务器 192.11.32.22(随机实例)
  1. 登录服务器
$ ssh root@192.11.32.22
  1. 安装 nginx 及相关命令
# 安装
$ yum install nginx -y

# 启动
$ nginx

# 关闭
$ nginx -s stop

# 重启
$ nginx -s reload
  1. Nginx 默认配置

    Nginx 配置文件通常在/etc/nginx下,cat nginx.conf 查看配置文件

    外网访问服务器 Web服务由 Nginx 提供,Nginx 需要配置静态资源的路径信息才能通过 URL 正确访问到服务器上的静态资源

    通过 IP 或 域名访问 看到类似页面

image.png

默认资源目录在 /usr/share/nginx/html Nginx 会将资源指向站点

  1. 修改 Nginx 配置

    我习惯静态资源放在服务器的 /data/www 下,修改配置 对应路径

  2. 静态资源文件 上传服务器

# scp [参数] [原路径] [目标路径]
$ scp -r E:/dist/* root@192.11.32.22:/data/www
  1. 浏览器访问 http://192.11.32.22

image.png

搭建完成