nginx 静态文件代理配置以及root与alias的区别

位置:首页>文章>详情   分类: 教程分享 > nginx教程   阅读(1658)   2024-04-17 10:27:45

1.root的用法

location /request_path/image/ {
    root /local_path/image/;
}

这样配置的结果就是当客户端请求 /request_path/image/cat.png 的时候, 
Nginx把请求映射为/local_path/image/request_path/image/cat.png


2.alias用法

location /request_path/image/ {
    alias /local_path/image/;
}

这时候,当客户端请求 /request_path/image/cat.png 的时候, 
Nginx把请求映射为/local_path/image/cat.png 

注意:alias中的路径最后必须跟上/ root的路径最后可跟可不跟,alias支持正则表达式路径root不支持

 

使用 alias映射具体某个文件配置参考

    location /itemDetail/oDKuHHCof5.txt {
        alias   /usr/share/nginx/html/validation/oDKuHHCof5.txt; 
        index  oDKuHHCof5.txt;
    }

提示:映射具体文件一般用作文件校验

 

 

标签: nginx root alias
地址:https://www.leftso.com/article/171.html

相关阅读

1.root的用法location /request_path/image/ { root /local_path/image/; } 这样配置的结果就是当客户端请求 /reques...
Linux(centos) nginx安装和nginx入门配置方法1.切换至root用户$su - 2.执行在线安装命令#yum install nginx -y 如果上面提示以下内容[root...
最近博客升级总是nginx原生的502页面,感觉有些不友好,特此研究了下502页面的配置nginx 502配置502页面核心配置 #502 page error_...
解决centos系统使用yum安装nginx启动时报错[::]:80 failed (97: Address family not supported by protocol)一般默认的使用yu...
nginx开启gzip压缩配置配置参考:server{listen443ssl;server_namet.example.com;#charsetkoi8-r;#access_log/var/l...
nginx代理Tomcat带路径的项目location / {                 proxy_pass http://localhost:8080/v1/;          ...
打开任务管理器发现一大堆nginx进程
最近网站被恶意访问了,了解了一些基础防护手段,nginx屏蔽ua访问 编写文件agent_deany.conf #使用方法 #创建目录 /etc/nginx/conf.d/deny...
centos 6 nginx+php7环境配置 做一记录,谨防采矿 $title(php.conf) # # The default server # server { l...
nginx常规使用时作为http协议的反向代理,这里要讲的是非http的Mysql端口代理,理论支持其他协议nginx.conf配置如下:user nginx; worker_process...