nginx伪静态配置实例

来源:互联网 发布:杰奇网络注册 编辑:程序博客网 时间:2024/06/05 00:25
server
{
listen       80;
server_name  bbs.jb51.net;
index index.html index.htm index.php;
root  /home/www/bbs;
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;


在ubuntu上部署成功的简单伪静态实例:
####################################################################
server{
       listen 80;
       root /usr/share/nginx/html;
       index index.php index.html index.htm;
       server_name localhost;
       error_page 404 /404.html;
   
   
       location / {
           #try_files $uri $uri/ /index.html;
           index index.html;
       }

       #设置/article/id 读取文章详情的伪静态
       location ~* ^/article/(\d+)$ {
                set $id $1;
  rewrite ^/article/(\d+)$ /article_detail.php?id=$1 last;
                #try_files $uri  /article_detail.php?id=$id;
        }
         
       #设置/news/m/id.html的伪静态
       location ~*  ^/news/m/(\d+).html {
 set $id $1;
        try_files $uri /news.php?id=$id;

       }
       
        #设置下载打伪静态
       location ~* ^/download/m/(.*).html {
            set $chanel $1;
            try_files $uri /$chanel.html;
        }
   
   
       location ~ \.php$ {
           fastcgi_pass 127.0.0.1:9000;
           fastcgi_index index.php;
           fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
           include /etc/nginx/fastcgi_params;
           
            #php404时触发error_page
            fastcgi_intercept_errors on;
       }
       
   }
######################################################################

1、当访问 首页时 如  127.0.0.1  会直接找index或index.html页面;
2、当访问 127.0.0.1/article/23 会直接访问 /article_detail.php?id=23;
3、当访问 127.0.0.1/news/m/23.html 会直接访问/news.php?id=23;
4、当访问127.0.0.1/download/m/xiaomi.html 会直接访问/xiaomi.html;
5、当找不到页面时会触发error_page规则,页面直接跳转到/404.html
0 0
原创粉丝点击