nginx 部署静态网站

nginx 部署静态网站

nginx 是一个高性能的 http 服务器,因此可以用于部署静态网站。

下面在 nginx 里部署 本地 index 静态网站项目

  1. 上传 index 文件夹到 nginx 安装目录 /usr/local/nginx

    可以使用 EditPlus 完成上传,也可以用其他方式。
    
    上传完后, /usr/local/nginx 下有:
    conf
    html
    index
    sbin
    
  2. 修改 nginx 配置文件 /usr/local/nginx/conf/nginx.conf

    nginx.conf 中有这么一段内容
    
    server {
        listen       80;
        server_name  localhost;
    
    
    
        location / {
            root   html;
            index  index.html index.htm;
        }
    
    
        error_page   500 502 503 504  /50x.html;
    
        location = /50x.html {
            root   html;
        }
    
    }
    
    修改为:
    
    server {
        listen       80;
        server_name  localhost;
    
    
    
        location / {
            root   index; # 定义 index 静态网站的根目录 / : /usr/local/nginx/index
            index  index.html index.htm;
        }
    
    
        error_page   500 502 503 504  /50x.html;
    
        location = /50x.html {
            root   html;
        }
    
    }
    
  3. 重新加载配置文件

    cd /usr/local/nginx/sbin
    ./nginx -s reload
    
  4. 访问静态资源

    本地火狐浏览器地址栏输入 192.168.214.128,就可以访问到部署在 nginx 里 index 文件夹下的 index.html
    静态资源部署成功!
posted @ 2020-08-30 21:41  学习java进行时  阅读(230)  评论(0编辑  收藏  举报