server {
listen ;
server_name localhost;
index index.html index.htm index.php;
root /data/wwwroot;
location /wordpress{
<span style="color:#ff0000;"><strong><em>try_files $uri $uri/ /wordpress/index.php?$args;</em></strong></span>
}
location ~ .*\.(php|php7)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
#伪静态设置路径 和日志文件路径
#include /etc/nginx/rewrite/default.conf;
access_log /data/wwwlogs/wordpress_access.log;
error_log /data/wwwlogs/wordpress_error.log;
}

根据上面的标准红色的字体“try_files $uri $uri/ /wordpress/index.php?$args;”为例,我们做如下说明:

当用户请求 http://blog.csdn.net/example 时,这里的 $uri 就是 /example。try_files 会到硬盘里尝试找这个文件。

如果存在名为 /$root/example(其中 $root 是 WordPress 的安装目录)的文件,就直接把这个文件的内容发送给用户。

如果不存在名为 叫 example 的文件。然后就看 $uri/,增加了一个 /,也就是看有没有名为 /$root/example/ 的目录。又找不到,就会 fall back 到 try_files 的最后一个选项 /index.php,发起一个内部 “子请求”,也就是相当于 nginx 发起一个 HTTP 请求到 http://blog.csdn.net/index.php。这个请求会被 location ~ \.php$ { ... } catch 住,也就是进入 FastCGI 的处理程序。而具体的 URI 及参数是在 REQUEST_URI 中传递给 FastCGI 和 WordPress 程序的,因此不受 URI 变化的影响。

nginx try_files 详解的更多相关文章

  1. Nginx高性能服务器安装、配置、运维 (3) —— Nginx配置详解

    四.Nginx 配置详解 YUM方式安装的Nginx默认配置文件放在/etc/nginx目录下,使用Vim编辑/etc/nginx/nginx.conf: ---------------------- ...

  2. Nginx Rewrite详解

    Nginx Rewrite详解 引用链接:http://blog.cafeneko.info/2010/10/nginx_rewrite_note/ 原文如下: 在新主机的迁移过程中,最大的困难就是W ...

  3. nginx配置详解(转)

    Nginx 配置文件详解 user nginx ; #用户 worker_processes 8; #工作进程,根据硬件调整,大于等于cpu核数 error_log logs/nginx_error. ...

  4. nginx之旅(第一篇):nginx下载安装、nginx启动与关闭、nginx配置文件详解、nginx默认网站

    一.nginx下载安装 版本nginx 1.15.5 系统环境centos7.5(本机ip192.168.199.228) 关闭selinux 和防火墙firewall 1.下载 wget http: ...

  5. Nginx配置详解 http://www.cnblogs.com/knowledgesea/p/5175711.html

    Nginx配置详解 序言 Nginx是lgor Sysoev为俄罗斯访问量第二的rambler.ru站点设计开发的.从2004年发布至今,凭借开源的力量,已经接近成熟与完善. Nginx功能丰富,可作 ...

  6. Nginx系列(10)- Nginx配置文件详解

    nginx文件结构 ... #全局块 events { #events块 ... } http #http块 { ... #http全局块 server #server块 { ... #server全 ...

  7. Nginx配置详解(转)

    转自:Nginx简介及配置文件详解 一 Nginx简介 Nginx是一款开源代码的高性能HTTP服务器和反向代理服务器,同时支持IMAP/POP3/SMTP代理服务 1.Nginx工作原理 Nginx ...

  8. Nginx配置文件详解

    Nginx是一款面向性能设计的HTTP服务器,相较于Apache.lighttpd具有占有内存少,稳定性高等优势. ######Nginx配置文件nginx.conf中文详解##### #定义Ngin ...

  9. Nginx中文详解、配置部署及高并发优化

      一.Nginx常用命令: 1. 启动 Nginx          /usr/local/nginx/sbin/nginxpoechant@ubuntu:sudo ./sbin/nginx2. 停 ...

随机推荐

  1. 【PAT】B1055 集体照(25 分)

    很简单的two points问题 ##注意:K是行数 #include<stdio.h> #include<string.h> #include<map> #inc ...

  2. js对象属性与Bom

    1JavaScript 的对象 1.1字符串 1.2Array对象 1.3Date对象 1.4Math对象 1.5Function对象(重点) 2 Bom对象 1   JavaScript对象 在Ja ...

  3. swift 该死的派发机制--待完成

    swift 该死的派发机制 final static oc类型 多态类型 静态类型 动态函数  静态函数 nsobject: 1.缺省不再使用oc的动态派发机制: 2.可以使用nsobject暴露出来 ...

  4. 解决jqueryeasyUI dialog 弹出窗体超出浏览器,导致不能关闭的bug

    使用panel的onMove事件攻克了panel,dialog以及window组件在被拖动时,会超出浏览器边界而无法拖回的情况. 当窗体被拖出浏览器有边界时.$(document).width();会 ...

  5. centos7下安装docker(11容器操作总结)

    这段时间主要是学习了对容器的操作,包括:容器的状态:start,stop,restart,rename,pause,unpause,rm,attach,exec,kill,logs:还学习了对容器的资 ...

  6. Domain Adaptation (3)论文翻译

    Abstract The recent success of deep neural networks relies on massive amounts of labeled data. For a ...

  7. js == 与 === 的区别[转]

    we文章转自http://blog.sina.com.cn/s/blog_4b32835b01014iv9.html 1.对于string,number等基础类型,==和===是有区别的 1)不同类型 ...

  8. MongoDB可视化工具--Robo 3T 使用教程

    MongoDB可视化工具--Robo 3T 使用教程 1. 到官网下载Robo 3T,网址如: https://robomongo.org/download. 2. 下载安装成功后,打开后点击左上角的 ...

  9. <<linux device driver,third edition>> Chapter 3:Char Drivers

    The Internal Representation of Device Numbers Within the kernel,the dev_t type(defined in linux/type ...

  10. Linux kernel 之 socket 创建过程分析

    重要结构体 struct socket 结构体 // 普通的 BSD 标准 socket 结构体 // socket_state: socket 状态, 连接?不连接? // type: socket ...