一个nginx匹配很诡异的问题,原因由权限引起

nginx配置如下:

location ~ \.php$ {
root /opt/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

}

按照道理说访问地址如:

xxx.com/statichtml/json.php

应该可以正常访问,可每次访问都是直接下载json.php文件,试了很多次,每次都是如此。

我自己创建一个phpinfo.php,安装目录

xxx.com/statichtml/phpinfo.php却可以正常访问。

难道是权限的问题??

看了下我自己创建phpinfo.php使用root身份创建的。

-rw-r--r-- 1 root  root   17 Sep 20 04:53 phpinfo.php

json.php却是:

-rwxrwxrwx 1 user1 root 4151 Sep 12 09:48 json.php*

创建者是user1.

发现问题不是上面,出在:

location ~* /statichtml/.*\.php$ {

root /opt/nginx/html/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

}

location ^~ /statichtml/ { 如果开启这个,json2.php就直接下载了。因为这个匹配会覆盖掉.php。不管放在前面还是后面。
root /opt/nginx/html/;

}

上面做法不对,

两个匹配不能区分静态文件和.php文件。

我改成:

location ~* /statichtml/.*\.(json|gif|jpg|png|jpeg|html|jpeg|css|js)$ {
   root /opt/nginx/html/;

}

可以解决问题。

后来想的办法:

location ~* /statichtml/.*\.php$ {

root /opt/nginx/html/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

}
location ~ /statichtml {

root /opt/nginx/html;
}

也可以。

参考文章:

nginx alias的设置

nginx也有像apache的别名功能,格式为:

location ~ /alias {root /home/www/default;index index.php;}

但nginx在处理php脚本时,需要传递给fastcgi才能处理,所以比apache的别名设置多一个,下面我们以phpmyadmin别名设置为例:

location ~ ^/phpmyadmin.+.php$ {root /home/www/default;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}location ~ /phpmyadmin {root /home/www/default;index index.php;}最后匹配理带有"~"和"~*"的指令,如果找到相应的匹配,则nginx停止搜索其他匹配;当没有正则表达式或者没有正则表达式被匹配的情况下,那么匹配程度最高的逐字匹配指令会被使用。参考:http://www.cnblogs.com/youxin/p/3944568.html
时间: 2024-08-27 11:09:14

一个nginx匹配很诡异的问题,原因由权限引起的相关文章

[转]一个用户SQL慢查询分析,原因及优化

来源:http://blog.rds.aliyun.com/2014/05/23/%E4%B8%80%E4%B8%AA%E7%94%A8%E6%88%B7sql%E6%85%A2%E6%9F%A5%E8%AF%A2%E5%88%86%E6%9E%90%EF%BC%8C%E5%8E%9F%E5%9B%A0%E5%8F%8A%E4%BC%98%E5%8C%96/ 问题描述 一个用户反映先线一个SQL语句执行时间慢得无法接受.SQL语句看上去很简单(本文描述中修改了表名和字段名):SELECT cou

通配符的匹配很全面, 但无法找到元素 'tx:annotation-driven'

配置Spring时出现如题这个错误,下面是xml的内容 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http:/

springMVC:通配符的匹配很全面, 但无法找到元素 &#39;mvc:annotation-driven&#39; 的声明

转自:http://blog.csdn.net/tolcf/article/details/50845483 报错信息:通配符的匹配很全面, 但无法找到元素 'mvc:annotation-driven' 的声明 原因是:虽然在xml文件上方声明了mvc,但没有配置此声明对应的文件信息,正确配置如下: <beans xmlns="http://www.springframework.org/schema/beans"       xmlns:xsi="http://ww

关于spring”通配符的匹配很全面, 但无法找到元素 &#39;context:component-scan&#39; 的声明“的错误

关于spring配置的问题 近日学习spring时遇到了这个问题: [html] view plain copy org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 12 in XML document from URL [file:/F: /workspace/spring/target/classes /applicationContext.xml] is invalid; nested ex

通配符的匹配很全面, 但无法找到元素

关于spring配置的问题 近日学习spring时遇到了这个问题: [html] view plain copy org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 12 in XML document from URL [file:/F: /workspace/spring/target/classes /applicationContext.xml] is invalid; nested ex

pconline注册页面很诡异的一堆请求

今天偶然发现pconline很诡异的一个现象 他的注册地址http://my.pconline.com.cn/passport/register.jsp 我用burp suite挂上后,发现一堆莫名其妙的请求出去了 啥都有qq的,baidu,阿里云的,pcgames啥的,很明显是在刷广告数据(其中qq的有的参数里还带adbXXXX.... 尝试联系qq的管家?不知道了) 诡异的事情来了, 我用firefox+firebug去看,居然正常!!!没有这些乱七八糟的请求 再换ie,又有了,但是ie打开

[bug]cxf: cvc-complex-type.2.4.c: 通配符的匹配很全面, 但无法找到元素 &#39; &#39;jaxws:server&#39; 的声明,问题处理

问题原因: 未知,因个人环境不同,无法保证都适用 问题解决方法: 将cxf在spring的配置信息调整到最前方 原配置信息头:     运行时错误提示: 调整后 提示页面 [bug]cxf: cvc-complex-type.2.4.c: 通配符的匹配很全面, 但无法找到元素 ' 'jaxws:server' 的声明,问题处理 原文地址:https://www.cnblogs.com/Vgger/p/8594426.html

通配符的匹配很全面, 但无法找到元素 &#39;xxxxxxxx&#39;

首先,一般配置通配符之前,你都会有如下xml头吧 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://

通配符的匹配很全面, 但无法找到元素 &#39;mvc:annotation-driven&#39; 的声明

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 14 in XML document from class path resource [spring-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 28; cvc-complex-