【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 ...
随机推荐
- IIS 伪静态 脚本映射 配置方法
首先,是IIS7.0的配置,由于Windows Server 2008操作系统默认的IIS版本为7.0,我们知道,IIS7.0与IIS6.0 核心注意的地方:先要将应用池设置为集成模式,修改OK后,再 ...
- deployment删除后,副本集未删除,解决之道
在删除的body上加上,body.setPropagationPolicy("Foreground");就可以删除deployment的同时连同副本集一同删除.
- Flask-Script-Migrate
Flask-Script 从字面意思上来看就是 Flask 的脚本 是的,熟悉Django的同学是否还记得Django的启动命令呢? python manager.py runserver 大概是这样 ...
- SublimeText插件 : sass语法高亮
安装 :sublime中安装sass插件和sass build插件 就可以高亮显示sass 步骤:安装 sass插件和sass build (安装过程不细说) 步骤2:打开.sass文件,进行以下设 ...
- 云集微助手安装教程和授权说明old
安装教程 一 .手机越狱(如果已经越狱请跳过此步,直接进行第二步) 越狱教程:http://jailbreak.25pp.com/yueyu/ 二 .安装触动精灵(如果你已安装触动精灵最新版请跳过此步 ...
- dojo事件绑定
Dojo如何动态绑定事件的小demo <html> <title>事件绑定测试test</title> <head></head> < ...
- Android基础Activity篇——其他隐式Intent
1.使用隐式Intent调用浏览器 修改FirstActivity中的按钮点击事件代码. Intent intent=new Intent(Intent.ACTION_VIEW); intent.se ...
- python模块详解 logging
打印日志的五个级别: import logging logging.debug('test debug') logging.info('test info') logging.warning('tes ...
- May 05th 2017 Week 18th Friday
No matter what have happened today, the sun will just rise in the morning of tomorrow. 无论今天发生了什么,明天早 ...
- Git-进阶-远程仓库的使用
一.远程仓库怎么玩 1. 自己搭建一个运行Git的服务器 Git是分布式版本控制系统,同一个Git仓库,可以分布到不同的机器上,但肯定有一台机器有着最原始的版本库,然后别的机器来克隆这个原始版本库,这 ...