首页 > 其他 > 详细

nginx访问静态文件配置

时间:2018-09-28 20:03:34      阅读:190      评论:0      收藏:0      [点我收藏+]

通过nginx访问静态文件配置,均是在server模块中配置,有两种方式:

1、alias

通过alias关键字,重定义路径,如

server{
    listen 7001;
    server_name 127.0.0.1;
    location /file/ {
        alias /home/china/areas/;
    }
}

此时,通过浏览器访问http://127.0.0.1:7001/file/t.txt,则访问服务器的文件是/home/china/areas/t.txt

alias可以使用正则表达式,如

location ~  ^/test/(\w+).(\w+)$ {
    alise /home/china/$2/$1.$2;
}

访问/test/t.conf,则实际访问的是/home/china/conf/t.conf

2、root

通过root关键字,重定义路径,如

server{
    listen 7002;
    server_name 127.0.0.1;
    location /test/ {
        root /home/china/areas/;
    }
}

此时,通过浏览器访问http://127.0.0.1:7001/test/t.txt,则访问服务器的文件是/home/china/areas/test/t.txt

上述两种方法均可达到目的,区别是它们对路径的解析方式不同,alas会把指定路径当作文件路径,

而root会把指定路径拼接到文件路径后,再进行访问。

--------------------- 本文来自 panda-star 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/chinabestchina/article/details/73556785?utm_source=copy 

nginx访问静态文件配置

原文:https://www.cnblogs.com/maohuidong/p/9720414.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!