Nginx的WordPress伪静态配置

星期日, 2012-11-25 | Author: Lee | php, wordpress | 5,505 views

Nginx的apache的伪静态配置:
找到到Nginx的配置文件,默认编译后的配置文件在/usr/local/nginx/conf/nginx.conf;
Ubuntu通过包安装的配置文件位于/etc/nginx/nginx.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
location / {
        index index.html index.php;
        if (-f $request_filename/index.html){
            rewrite (.*) $1/index.html break;
        }
        if (-f $request_filename/index.php){
            rewrite (.*) $1/index.php;
        }
        if (!-f $request_filename){
            rewrite (.*) /index.php;
        }
    }
    location ~ .*\.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
    }

注解:此配置考虑了目录下的索引文件index.html和index.php。
-f指令表示测试文件是否存在(不考虑文件和目录的区别),
!-f则表示不存在。
注意在重写url到index.html后面有个break,而重写到index.php后没有break。(可以根据自己的情况配置多个跳出操作等)
因为html文件不需要任何额外工作可以直接发送到客户端,所以重写规则在这里终止,下面就直接让nginx发送文件。
而.php文件需要进一步发送到fastcgi进程来运行,Nginx会继续判断该文件符合第二个部分location ~ .*\.php$的规则,并进行FastCGI的转发。

WordPress的apache的伪静态配置:

1
2
3
4
5
6
7
8
9
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

注: 如果当请求的文件不存在,那么把请求内部重定向到/index.php.WordPress会自己分析请求的URL,来判断显示哪个页面。

Tags: , ,

文章作者: Lee

本文地址: https://www.pomelolee.com/1053.html

除非注明,Pomelo Lee文章均为原创,转载请以链接形式标明本文地址

No comments yet.

Leave a comment

Search

文章分类

Links

Meta