CentOS 7 环境下 Nginx 安装 WordPress 后开启 rewrite 伪静态

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

server {
        listen 80;
        server_name chaishiwei.com www.chaishiwei.com;
        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;
    }
}
上一篇 下一篇

 

© 2017 老柴的宅. Powered by Chaishiwei.com. 鄂ICP备11006811号