完美Nginx配置

网上的TP nginx配置,就当是学习nginx了.

完美支持4种url模式

静态文件404不跑fastcgi浪费资源

没有多于的IO浪费

,别怪我没提醒你收藏哦

server{

listen80;

server_name  thinkphp.lo;

root/var/www;

index  index.html index.htm index.php;

error_page404/404.html;

location=/404.html {

return 404 'Sorry, File not Found!';

}

error_page  500 502 503 504  /50x.html;

location=/50x.html {

root   /usr/share/nginx/html;# windows用户替换这个目录

}

location/{

try_files $uri@rewrite;

}

location@rewrite{

set$static0;

if($uri~\.(css|js|jpg|jpeg|png|gif|ico|woff|eot|svg|css\.map|min\.map)$){

set$static1;

}

if($static=0){

rewrite^/(.*)$ /index.php?s=/$1;

}

}

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

deny all;

}

location~\.php/{

if($request_uri~^(.+\.php)(/.+?)($|\?)){}

fastcgi_pass127.0.0.1:9000;

include fastcgi_params;

fastcgi_param SCRIPT_NAME     $1;

fastcgi_param PATH_INFO       $2;

fastcgi_param SCRIPT_FILENAME $document_root$1;

}

location~\.php${

fastcgi_pass127.0.0.1:9000;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

location~/\.ht{

deny  all;

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Nginx简介 解决基于进程模型产生的C10K问题,请求时即使无状态连接如web服务都无法达到并发响应量级一万的现...
    魏镇坪阅读 6,313评论 0 9
  • 《老男孩Linux运维》笔记 隐藏Nginx软件版本号 一般来说,软件的漏洞都和版本有关。因此要尽量隐藏对访问用户...
    Zhang21阅读 9,101评论 0 28
  • 1.ngnix介绍 ngnix www服务软件 俄罗斯人开发 开源 性能很高 本身是一款静态WWW软件 静态小文件...
    逗比punk阅读 6,382评论 1 6
  • nginx重写规则 nginx rewrite 正则表达式匹配 大小写匹配 ~ 为区分大小写匹配 ~* 为不区分大...
    桖辶殇阅读 10,897评论 0 2
  • 我知道,一提起玉米片,你脑海中浮现的图像大概是这样的: 不过,对于老美而言,他们更熟悉的玉米片,其实是长这样的: ...
    企鹅吃喝指南阅读 5,117评论 1 11