CentOS 7 环境下 Nginx 安装 WordPress 后开启 rewrite 伪静态
本文最后更新于 2083 天前,其中的信息可能已经有所发展或是发生改变。

曾经在 CentOS 6.5 环境下的 Nginx 开启 WordPress 伪静态用的是如下配置,WordPress 并不在根目录而是在二级目录下:

server {
        listen 80;
        server_name chaisw.cn www.chaisw.cn;
        index index.php index.html;
        root /www/;

        location ~ \.php$ {
                fastcgi_pass 127.0.0.1:9000;
                include fastcgi.conf;
        }

        location /blog/ {
            if (!-e $request_filename) {
                rewrite (.*) /blog/index.php;
            }
        }

        location ~ /phpmyadmin/.+\.php$ {
            if ($fastcgi_script_name ~ /phpmyadmin/(.+\.php.*)$) {
            set $valid_fastcgi_script_name $1;
            }
        include        fastcgi_params;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME /www/phpmyadmin/$valid_fastcgi_script_name;
        }
}

如今在 CentOS 7 的环境下,一样是二级目录放 WordPress,使用如上配置后,打开任何文章页面都显示404,样式等文件也无法加载显示404,Google 了很多方法,都没有效果,最后通过以下配置才解决伪静态的问题:

server {
    listen       80;
    server_name  localhost;

    root   /usr/share/nginx/www;
    index  index.php index.html index.htm;

    location /blog/ {
         if (!-e $request_filename) {
            rewrite (.*) /blog/index.php;
         }
    }

    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/www;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/www;
    }

    location ~ \.php$ {
        root           /usr/share/nginx/www;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}
本作品采用 “知识共享署名-非商业性使用 4.0 国际许可协议” 进行许可。
免责声明:本站文章除特殊说明为原创禁转外,您可以自由的转载和修改,但请务必注明文章来源并不可用于商业目的。
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇