<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Nginx on 两点之间</title><link>https://yuehei.37net.com/tag/nginx/</link><description>Recent content in Nginx on 两点之间</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Fri, 08 Oct 2010 04:26:21 +0000</lastBuildDate><atom:link href="https://yuehei.37net.com/tag/nginx/index.xml" rel="self" type="application/rss+xml"/><item><title>nginx下wordpress的rewrite</title><link>https://yuehei.37net.com/2010/10/nginx_wordpress_rewrite/</link><pubDate>Fri, 08 Oct 2010 04:26:21 +0000</pubDate><guid>https://yuehei.37net.com/2010/10/nginx_wordpress_rewrite/</guid><description>&lt;p&gt;国庆前买了 &lt;a href="http://www.linode.com/" target="_blank" rel="nofollow" &gt;linode&lt;/a&gt; 的VPS，算是edong撤走了，不用再去照相了，照相这种备案方式和以前BBS专项备案一样，没有什么操作性，迟早也要取消的。以前用edong vps，跑的是nginx+apache，这次直接换成nginx+spawn-fcgi。&lt;/p&gt;
&lt;pre lang="apache"&gt;# BEGIN WordPress
&amp;lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
&amp;lt;/IfModule&gt;
# END WordPress
&lt;/pre&gt;
&lt;p&gt;上面是推荐的rewrite规则，但是这样规则会将不存在的图片,css等文件也都转发到index.php，这些文件应该报个404的。&lt;/p&gt;
&lt;pre lang="apache"&gt;#现在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;
 }
 }
&lt;/pre&gt;
&lt;p&gt;测试一下: &lt;a class="link" href="https://yuehei.37net.com/test_test.png" target="_blank" rel="noopener"
 &gt;https://yuehei.37net.com/test_test.png&lt;/a&gt; 报的是404了&lt;/p&gt;</description></item></channel></rss>