Nginx_静态资源处理

静态资源处理的需求:

因为nginx处理静态资源的效率高于tomcat服务器,所以,对于常用的静态资源,可直接交友nginx进行访问处理。
方法一:应用举例:
1、在nginx文件夹下新建static文件夹(与conf平级),再新建项目名称文件夹(例如maven_exam)。
2、将静态资源(js/css/html/图片等)放入static/maven_exam目录下
3、修改conf / nginx.conf配置文件的 server块配置中

        location / {
        	# 根目录配置  Linux配置:opt/static/maven_exam
            root   D:/development/nginx-1.16.1/static/maven_exam; #  windows配置方式
            index  index.html index.htm;
        }

4、配置成功以后,路径(http://localhost/el.jpeg)可直接访问到静态资源el.jpeg这个图片,说明配置成功。
Nginx_静态资源处理_第1张图片
方法二:应用举例:
1、在nginx文件夹下的html文件夹下,新建项目名称文件夹(例如maven_exam)。
2、将静态资源(js/css/html/图片等)放入html/maven_exam目录下。
3、conf / nginx.conf配置文件的 server块配置中,为默认配置如下即可。

        location / {
            root   html;
            index  index.html index.htm;
        }

4、配置成功以后,路径(http://localhost/maven_exam/el.jpeg)可直接访问到静态资源el.jpeg这个图片,说明配置成功。

你可能感兴趣的:(运维,nginx)