【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 ...
随机推荐
- HBase Shell基本使用总结
创建一个表 hbase(main):002:0> create 'member', 'cf_tmp', 'address', 'info' 查看所有表清单 hbase(main):003:0&g ...
- Html+CSS二周目--->常用概念
学习css几乎俩周,来总结一下 对于初学者来说,有一些基本的概念是我们应当清楚的.掌握这些概念,可以帮助你更加有效的开发,大大提高开发效率. 1.盒子模型 2.浮动(float) 3.定位(posit ...
- springmvc实现文件下载到Android手机设备pda端
1:首先要添加相关得jar文件,在pom.xml中 <dependency> <groupId>commons-fileupload</groupId> <a ...
- js 浮点数计算Bug
之前在写项目时候,直接对带小数点的数据进行运算,发现所得到的值并不是自己想要的. 经过一系列学习后,发现在JavaScript中,浮点数运算都是先转换成二进制,在转成二进制的时候有出现无限循环小数,故 ...
- 设置Tomcat的字符编码
在 server.xml 中的 Connector 标签在加入 URIEncoding="UTF-8" 属性. <Connector port="8080" ...
- vue本地和线上环境(域名)配置
vue本身为运行脚手架项目自家搭载了一个nodejs后台环境,本地可通过proxyTable来处理跨域问题,但是上线(或生产环境)之后改域名真是一件麻烦的事情,所以进行一些配置. config/ind ...
- android 扇形菜单
引言: android中的菜单与windows的菜单没有什么区别,基本就是一个矩形框,如下: 这个菜单有多么能经得住历史的考验我就不多说了!我们再来看看最新有关手机可操作区域的调查 有此可以看出屏幕越 ...
- Android AS升级3.1 编译报错:The SourceSet 'instrumentTest' is not recognized by the Android Gradle Plugin.
AndroidStudio升级到3.1后编译报错:The SourceSet ‘instrumentTest’ is not recognized by the Android Gradle Plug ...
- 监控系统-nagios
https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/ install yum -y install nagios-4 ...
- C#保存图片到数据库并读取显示图片的方法
private void button2_Click_1(object sender, System.EventArgs e) { string pathName; if (this.openFile ...