【nginx】root alias 区别,以及server root , location root 区别
最近在研究前后端分离站点配置在同一域名下,发现
root
,alias
有区别,而且所有的root
如果都放置在location
下面访问无效的问题,才有此总结,本文只是作者自己的个人见解,非喜勿喷
root , alias 区别
root
的配置 带匹配路径的
location /i/ {
root /data/w3/;
}
### 如果访问 www.domain.com/i/test.png 最后返回的结果为 /data/w3/i/test.png ,root 配置最后的/要不要都行
alias
的配置 不带匹配路径的,而且最后一定要加/,nginx可以处理多个////为一个/
location /i/ {
alias /data/w3/;
}
### 如果访问 www.domain.com/i/test.png 最后返回的结果为 /data/w3/test.png ,root 配置最后的/一定是要的,否则返回结果会变成 /data/w3test.png 而返回的404
server root , location root 区别
root 指的是请求的根目录,引用nginx官网的解释:
Sets the root directory for requests . A path to the file is constructed by merely adding a URI to the value of the root directive 翻译:设置请求的根目录,设置的文件路径要加上root后面匹配的URI
Note that the root directive is placed in the server context. Such root directive is used when the location block selected for serving a request does not include own root directive. 如果匹配的location里面没有自己的root指令,才用server里面的root指令
总结:location里面的root优先级高于server
### 如果不想使用root的目录转换功能而需要做重定向,应该提取root在location的外面
root "C:/Users/flint/PhpstormProjects/basic/web/";
location ~ ^/admin/ {
index test.php ;
autoindex on;
try_files $uri $uri/ /test.php?$args;
}
贴上完整的 xc.com 站点配置文档 xc.com.conf
server {
listen 80;
server_name xc.com;
charset utf-8;
root "C:/Users/flint/PhpstormProjects/basic/web/";
location ~ ^/admin/ {
index test.php ;
autoindex on;
try_files $uri $uri/ /test.php?$args;
}
location / {
root "E:/vue-admin-template/dist";
set $cors_origin "";
if ($http_origin ~* "^xc.com:9528$") {
set $cors_origin $http_origin;
}
if ($http_origin ~* "^xc.com$") {
set $cors_origin $http_origin;
}
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin $cors_origin;
add_header Access-Control-Allow-Headers *;
add_header Access-Control-Allow-Methods POST,OPTIONS;
add_header Access-Control-Allow-Credentials true;
return 204;
}
index index.html ;
autoindex on;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
【nginx】root alias 区别,以及server root , location root 区别的更多相关文章
- nginx 图片访问404 (使用location中使用 root,alias的区别)
问题描述: 在/data/code_img/文件下有很多验证码图片,想将他们展示出来 希望通过 http://127.0.0.1/img/1.png 这种形式访问到对应图片,刚开始nginx中配置如下 ...
- nginx文件路径配置(root|alias)
nginx指定文件路径主要有两种方式:root|alias. 那么他们究竟有什么区别呢? 指令的使用方法和作用域: [root] 语法:root path 默认值:root html 配置段:http ...
- nginx.conf 配置解析之 server配置
server{} 包含在http{}内部,每一个server{}都是一个虚拟主机(站点) 以下为nginx.conf配置文件中server{ }部分的内容. server { listen ; // ...
- nginx的location root alias指令以及区别
原文:http://blog.csdn.net/bjash/article/details/8596538 location /img/ { alias /var/www/image/; } #若按照 ...
- Nginx设置alias实现虚拟目录 alias与root的用法区别
Nginx 貌似没有虚拟目录的说法,因为它本来就是完完全全根据目录来设计并工作的.如果非要给nginx安上一个虚拟目录的说法,那就只有alias标签比较"像",干脆来说说alias ...
- Nginx的alias的用法及与root的区别
以前只知道Nginx的location块中的root用法,用起来总是感觉满足不了自己的一些想法.然后终于发现了alias这个东西. 先看toot的用法 location /request_path/i ...
- Nginx(alias 和 root的区别)
Nginx(alias 和 root的区别)1.alias 和 root 的区别: location /request_path/image { root /local_path/image/; } ...
- 【03】Nginx:location / root / alias
写在前面的话 前面我们谈了 nginx 基础的 WEB 服务配置以及定制我们的日志显示格式,接下来我能更加详细的说说 server 字段. location 字段 在 Server 中,如果我们只是一 ...
- nginx之location(root/alias)
location配置 1. 语法规则(按优先级) = 表示精确匹配,优先级最高 ^~ 表示uri以某个常规字符串开头,用于匹配url路径(而且不对url做编码处理,例如请求/s ...
随机推荐
- HttpClient4.3.3 禁止自动重定向
HttpClient4.3中默认允许自动重定向,导致程序中不能跟踪跳转情况,其实只需要在RequestConfig中setRedirectsEnabled(false)即可(默认是true): pri ...
- hibernate课程 初探一对多映射2-3 创建hibernateUtil工具类
本节主要内容:创建hibernateUtil工具类:demo demo: HibernateUtil.java package hibernate_001; import org.hibernate. ...
- 从零开始的全栈工程师——js篇2.18(js的运动)
一.元素的 client offset scroll 三个系列 clientWidth / clientHeight / clientTop / clientLeftoffsetWidth / off ...
- 基于FPGA的VGA显示设计(二)
上一篇:基于FPGA的VGA显示设计(一) 参照 CrazyBingo 的 基于FPGA的VGA可移植模块终极设计代码 的工程代码风格,模块化处理了上一篇的代码,并增加了一点其它图形. 顶层 ...
- poj 3485 区间选点
题目链接:http://poj.org/problem?id=3485 题意:X轴上公路从0到L,X轴上下有一些点给出坐标代表村庄,问在公路上最少建几个出口才能使每个村庄到出口的距离不超过D. 以村庄 ...
- 模拟停车POJ(3505)
题目链接:http://poj.org/problem?id=3505 解题报告: #include <stdio.h> #include <iostream> #includ ...
- 问题 C: P4 游戏中的Human角色
题目描述 在一个平面打斗游戏中,任何的角色(Role)都有血量(blood)和位置loc(此处loc是Location类的实例)属性.有了Role类,可以派生出不同的角色,如人.神仙.怪兽等.如下程序 ...
- redis 有序集合类型
- Mybatis中的DataSource配置
dataSource 的类型可以配置成其内置类型之一,如 UNPOOLED,POOLED,JNDI. 1.如果将类型设置成 UNPOOLED,MyBatis 会为每一个数据库操作创建一个新的连接,并关 ...
- 【Oracle-DBA】Oracle连接非常慢APPARENT DEADLOCK
我是一名软件包工头,哪里有问题就干哪里. 这次是 Oracle 出毛病了,我就临时兼了DBA的职,没办法,谁叫我是工头呢.打开百度就开干. 这次关键词是:APPARENT DEADLOCK!!! 丫的 ...