work hard work smart

专注于Java后端开发。 不断总结,举一反三。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Nginx 静态资源配置

Posted on 2020-06-13 13:06  work hard work smart  阅读(451)  评论(0编辑  收藏  举报

1、配置静态前端工程

server {
        listen       80;
        server_name  localhost;

        location / {
            root   /home/files/uploadStaticResource/folder1;
            #root   html;
            index   index.html;
        }

     }

 folder1文件夹就是存放的前端工程,里面放着一个index.html文件 

 

2、配置资源

server {
        listen       80;
        server_name  localhost;

        location / {
            root   /home/files/uploadStaticResource/folder1;
            #root   html;
            index   index.html;
        }

        location /resource {
            root   /home/files/uploadStaticResource;
         }


     }

  在/home/files/uploadStaticResource文件夹下放着一个resource文件夹

 

 访问测试:

 

使用别名的方式配置静态资源

location /static {
            alias   /home/files/uploadStaticResource/resource;
         }

 访问方式: http://www.xxx.xx/static/imgs/1.jpg