nginx下wordpress的rewrite

国庆前买了 linode 的VPS,算是edong撤走了,不用再去照相了,照相这种备案方式和以前BBS专项备案一样,没有什么操作性,迟早也要取消的。以前用edong vps,跑的是nginx+apache,这次直接换成nginx+spawn-fcgi。

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

上面是推荐的rewrite规则,但是这样规则会将不存在的图片,css等文件也都转发到index.php,这些文件应该报个404的。

    #现在nginx上使用的rewrite
    server {
        server_name yuehei.37net.com;
    
        access_log   /var/log/nginx/yuehei_37net_com_access.log main;
        error_log     /var/log/nginx/yuehei_37net_com_error.log info;

        root  /data/html/37net.com/yuehei;
        index index.html index.htm index.php;
        
        error_page  403  =200 /403.html;
        location = /403.html {
            root /data/html;
        }
        error_page  404  =200 /404.html;
        location = /404.html {
            root /data/html;
        }
        
        location / {
            if (!-e $request_filename) {
                rewrite ^(.*)$ /index.php last;
                break;
            }
        }

        location ~ \.(gif|jpg|jpeg|png|css|js)$ {
            expires 365d;
        }

        location ~ \.php$ {
            include /etc/nginx/fastcgi_params;
        }
    }

测试一下: http://yuehei.37net.com/test_test.png 报的是404了

此条目发表在platform分类目录,贴了, , 标签。将固定链接加入收藏夹。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据