Nginx伪静态配置和经常使用Rewrite伪静态规则

伪静态是一种能够把文件后缀改为任何可能的一种方法,若是我想把PHP文件伪静态成html文件,这种至关简单的,下面来介绍nginx 伪静态配置方法有须要了解的朋友可参考。php

nginx里使用伪静态是直接在nginx.conf 中写规则的,并不须要像apache要开启写模块(mod_rewrite)才能进行伪静态。html

nginx只须要打开nginx.conf配置文件,在server里面写须要的规则便可。nginx

server 

listen       80; 
server_name  bbs.jb51.net; 
index index.html index.htm index.php; 
root  /home/www/bbs;apache

 

error_page  404                                             /404.htm;       #配置404错误页面 
location ~ .*.(php|php5)?$ 

#fastcgi_pass  unix:/tmp/php-cgi.sock; 
fastcgi_pass  127.0.0.1:9000; 
fastcgi_index index.php; 
include fcgi.conf; 
}服务器

#下面就是伪静态了网站

location /{ 
rewrite ^(.*)/equip(d+).html$ $1/index.php?m=content&c=index&a=lists&catid=$2 last; 

access_log  access_log   off; 
ui

而后重启nginx服务器伪静态就生效了,这种维护起来非常不方便咱们能够把它写在外部文件如bbs_nginx.conf中.net

在/home/www/bbs目录下建立bbs_nginx.conf文件并写入如下代码:unix

ocation /{ 
rewrite ^(.*)/equip(d+).html$ $1/index.php?m=content&c=index&a=lists&catid=$2 last; 
server

而后在上面的代码后面加上以下代码:

include /home/www/bbs/bbs_nginx.conf;

这样网站根目录中的bbs_nginx.conf伪静态规则,便可实现单独管理。

相关文章
相关标签/搜索