nginx有关.htaccess小结
可能很多朋友都常用nginx不支持.htaccess,只有apache才支持.htaccess文件,其实这是错误的看法nginx也是支持.hatccess的哦.
其实nginx和.htaccess一点关系都没有,只是一大堆人深受apache的影响觉得nginx应该也要支持.htaccess功能。在nginx的配置中直接include .htaccess文件就好
include /站点目录/.htaccess;
多么简单,但是更让人哭笑不得的是有大部分人根本就不知道nginx与apache是两个不同webserver程序,于是不少人这么干:在nginx里include .htaccess文件后,把apache伪静态规则的.htaccess上传到站点根目录下...无语。其实nginx可以include任何文件,而不仅仅是.htaccess。
其实nginx这样引用.htaccess跟apache还是有区别的,写法也不同:
1、nginx是启动引入,因为nginx特别注重效率,所以启动的时候会把所有的配置文件读入内存,然后启动个。如果发现有语法错误,则启动失败。而apache则是动态引入,每次访问站点都会重新载入配置。
2、nginx中的include是手动添加,指定目录。apache已经把.htaccess作为它的一种特色机制,并且支持站所有子目录都可以有.htaccess文件。
(以下摘自http://wiki.nginx.org/LikeApache-htaccess)
Like Apache: .htaccess
You can't do this. You shouldn't. If you need .htaccess, you're probably doing it wrong.
Why?
This is a great question. For starters, for .htaccess to work Apache needs to check EVERY directory in the requested path for the existence of a .htaccess file and if it exists it reads EVERY one of them and parses it. This happens for EVERY request. Remember that the second you change that file, it's effective. This is because Apache reads it every time.
Numbers
http://example.com/site/files/images/layout/header.png
Let's say we're not doing any funky aliasing and the file system looks like the path. This covers most of the sites out there. There is the / directory, then site/, files/, images/, and layout/. This amounts to 5 directories that could have a .htaccess file. Let's say you added a .htaccess in /, files/ and images/. That's three .htaccess files. That's pretty typical.
Now the numbers, that's 6 file system stats and 4 file system reads. Including one for the requested file. This happens for every read. We'll ignore parsing time because both Nginx and Apache need to do this and we'll consider the difference in time for this negligible.
| Requests [Per Hour] | Nginx FS Stats | Nginx FS Reads | Apache FD Stats | Apache FS Reads | Comment |
| 1 | 1 | 1 | 6 | 4 | Single Request [Pretty much no load] |
| 10 | 10 | 10 | 60 | 40 | Ten Requests [Pretty much no load] |
| 3,600 | 3,600 | 3,600 | 21,600 | 14,400 | 1 req/sec [Very low load] |
| 144,000 | 144,000 | 144,000 | 864,000 | 576,000 | 40 req/sec [Moderate traffic - nothing very large] |
| 324,000 | 324,000 | 324,000 | 1,944,00 | 1,296,000 | 90 req/sec [Higher traffic site - not massive] |
| 576,000 | 576,000 | 576,000 | 3,456,000 | 2,304,000 | 160 req/sec [Pretty high traffic - still not massive though] |
More Numbers
The default for Apache is to use AllowOverride All. Let's look at this for a Drupal website. One image for the theme. If you're website DocRoot is at /var/www/drupal6/ then we just added more file system stats. This adds 3 stats per request. This is an incredibly common Apache/Drupal setup. It's the end result of countless guides out there.
/var/www/drupal6/sites/example.com/themes/yourtheme/images/layout/header.png
Two .htaccess files will be in this path unless you create your own.
I'll be assuming you added one in /var/www/ because this is common.
| Requests [Per Hour] | Nginx FS Stats | Nginx FS Reads | Apache FD Stats | Apache FS Reads | Comment |
| 144,000 | 144,000 | 144,000 | 1,296,000 | 576,000 | 40 req/sec |
| 324,000 | 324,000 | 324,000 | 2,916,000 | 1,296,000 | 90 req/sec |
| 576,000 | 576,000 | 576,000 | 51,840,000 | 2,304,000 | 160 req/sec |
Conclusion
Stop using .htaccess. It's horrible for performance. Nginx is
designed to be efficient. Adding something like this would destroy that.
nginx有关.htaccess小结的更多相关文章
- nginx支持.htaccess文件实现伪静态的方法
方法如下: 1. 在需要使用.htaccess文件的目录下新建一个.htaccess文件, vim /var/www/html/.htaccess 2. 在里面输入规则,我这里输入Discuz的伪静态 ...
- 让nginx支持.htaccess文件实现伪静态的方法!
搞了个VPS,装了个LNMP一键安装包,然后搞了个程序放上,想实现伪静态,但是lnmp的默认规则里没有河蟹男需要的伪静态文件,得自己配置, 以前只在.htaccess里搞下就行,现在换Linux下ng ...
- Linux下nginx支持.htaccess文件实现伪静态的方法!
在Google上搜索的资料很多人都说nginx目前不支持.htaccess文件,我按照nginx的规则试验了一下,结果发现nginx是完全支持.htaccess文件的! 方法如下: 1. 在需要使用. ...
- nginx基础知识小结
配置文件讲解: #user nobody; #开启进程数 <= CPU数 worker_processes 1; #错误日志保存位置 #error_log logs/error.log; #er ...
- nginx配置.htaccess伪静态
https://blog.csdn.net/moqiang02/article/details/37695775
- linux Nginx VirtualHost虚拟主机多站点设置
linux系统CentOS7 Nginx1.9.9 一台nginx服务器同一IP被注册多个不同域名,访问不同域名到该服务器后请求不同项目 本台nginx服务器的IP地址为 192.168.155.12 ...
- Linux下Nginx+PHP 简单安装配置
测试环境 Linux 2.6.18nginx-1.0.4 http://www.nginx.org/php-5.3.6 http://www.php.net/ 一,安装Nginxwget http:/ ...
- Nginx配置信息损毁又无备份时如何恢复
worker_processes *; 本文介绍在Nginx配置信息出现问题后,在没有备份的情况下,如何利用Nginx进程的虚拟内存恢复配置信息. 问题背景 假设 /etc/nginx/site-av ...
- nginx 反向代理服务
目录 Nginx代理服务基本概述 Nginx代理服务常见模式 Nginx代理服务支持协议 Nginx反向代理配置语法 Nginx反向代理场景实践 配置代理实战 在lb01上安装nginx Nginx代 ...
随机推荐
- Linux下安装mongodb详细过程
本次安装mongodb使用yum.repo方式.详细过程请参考,也列出一些安装过程中的错误,欢迎指正. mongodb版本:3.0 先在linux下cd 到 /etc/yum.repos.d/ 新建脚 ...
- Android填坑系列:在小米系列等机型上放开定位权限后的定位请求弹框
背景: 近期因实际项目需要,在特定操作下触发定位请求,取到用户位置及附近位置. 问题: 经初步选型,最终决定接入百度定位,按照百度定位SDK Android文档,接入过程相对顺利.但随后发现,在小米系 ...
- HTTP错误大全 404 200 501 502 505
HTTP错误 大全 403 401 400 404 304 200 HTTP 400 - 请求无效 HTTP 401.1 - 未授权:登录失败 HTTP 401.2 - 未授权:服务器配置问题导致登录 ...
- IoC和DI的理解
1 概述 当我们想闭上眼睛想如何让我们的软件更加可用可维护时,我们总能想到一个词:松耦合.在这篇文章中,主要讲述了模块间存在的依赖关系,但这种依赖关系违背了依赖倒置原则.在这之后,我们将讨论一种解除软 ...
- C#如何根据配置实现动态窗体
本文主要讲述如何根据UI配置来动态生成控件, 并添加到窗体上来构建UI窗体,当用户在每个控件上完成输入操作后,程序通过遍历控件并用拼接字符串的方式动态生成Insert SQL语句,进而实现了将UI上的 ...
- 【HTML5】HTML5本地数据库(Web Sql Database)
Web Sql数据库简介 Web SQL数据库API实际上不是HTML5规范的组成部分,而是单独的规范.它通过一套API来操纵客户端的数据库. Web SQL数据库的浏览器支持情况 Web SQL 数 ...
- Angularjs 的 ngInfiniteScroll 的使用方法
Angularjs 的 ngInfiniteScroll 的使用方法 一.介绍 ngInfiniteScroll 是一个 AngularJS 的扩展指令,实现了网页的无限滚动的功能,也就是相当于页面滚 ...
- Moqui简介
Moqui简介 Moqui是一个生态系统理念,是需要一系列的能够用于构建企业自动化办公的开源软件的组合,如:eCommerce, ERP, CRM, SCM, MRP, EAM, POS, 等等. 架 ...
- 电商CRM的痛点在哪里?
观电商风云,风起云涌,如何寻找新客户及维护老客户,抢占市场,此时迫在眉睫.在大家所认为的CRM就是发发短信,发发邮件等形式去推送活动信息,但在三疯看来,做CRM的关键词是“互动”,而不是简单的促销. ...
- SharePoint 部署解决方案Feature ID冲突
中文报错: 部署步骤“添加解决方案”中出现错误: 已在此服务器场中安装 ID 为 735efe4e-8b50-4310-b588-c6ae2ba0759f 的功能.请使用强制属性显式地重新安装此功能. ...