全球主机交流论坛

标题: nginx下的wordpress固定连接 [打印本页]

作者: 遍地阳光    时间: 2009-11-1 11:05
标题: nginx下的wordpress固定连接
这个是主机配置文件

server
{
  listen       80;
  server_name www.abc.com;
  index index.html index.htm index.php;
  root  /web/www/abc;
  location ~ .*\.(php|php5)?$
   {
    fastcgi_pass  unix:/tmp/php-cgi.sock;
    #fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    include fcgi.conf;
   }
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
   {
    expires      30d;
   }
  location ~ .*\.(js|css)?$
   {
    expires      12h;
   }
  access_log   off;
}


www.adc.com是域名,在abc.com/blog下有个博客是wordpress的,
找到的wordpress在nginx下的规则是


location / {
        index index.html index.htm index.php;
        root /home/www/abc/blog;
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;
        }
}


红体字那部分写的对吗?
作者: rdpof    时间: 2009-11-1 11:19
那个跟wordpress固定连接一点关系都没有

是你的主目录路径
  1. if (-f $request_filename/index.html){
  2.                 rewrite (.*) $1/index.html break;
  3.         }
  4.         if (-f $request_filename/index.php){
  5.                 rewrite (.*) $1/index.php;
  6.         }
  7.         if (!-f $request_filename){
  8.                 rewrite (.*) /index.php;
  9.         }
  10. }
复制代码
这个才是关系性的固定链接,也就是rewrite规则.
我也是用这段代码,基本正常.

[ 本帖最后由 rdpof 于 2009-11-1 11:20 编辑 ]
作者: gdtv    时间: 2009-11-1 11:22
我一直用这个rewrite规则,多简单:

                if (!-e $request_filename) {
                        rewrite ^(.*)$ /index.php?q=$1 last;
                }
作者: 遍地阳光    时间: 2009-11-1 11:23
标题: 回复 2# 的帖子
这句代码该怎么写啊,我都给弄糊涂了,网上说啥的也有,可能是环境不太一样吧,所以我也一直没有成功,
你可以帮我把这个修改下吗?

server
{
  listen       80;
  server_name www.abc.com;
  index index.html index.htm index.php;
  root  /web/www/abc;
  location ~ .*\.(php|php5)?$
   {
    fastcgi_pass  unix:/tmp/php-cgi.sock;
    #fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    include fcgi.conf;
   }
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
   {
    expires      30d;
   }
  location ~ .*\.(js|css)?$
   {
    expires      12h;
   }
  access_log   off;
}
谢谢了。
作者: 遍地阳光    时间: 2009-11-1 11:24
标题: 回复 3# 的帖子
用了你那个了,我这里不行的。
作者: cpuer    时间: 2009-11-1 11:33
原帖由 gdtv 于 2009-11-1 11:22 发表
我一直用这个rewrite规则,多简单:

                if (!-e $request_filename) {
                        rewrite ^(.*)$ /index.php?q=$1 last;
                }


我以前测试也是用的你这个规则
作者: 遍地阳光    时间: 2009-11-1 11:38
标题: 回复 6# 的帖子
能用吗?
作者: cpuer    时间: 2009-11-1 11:40
server
        {
                listen       80;
                server_name www.abc.com;
                index index.html index.htm index.php;
                root  /web/www/abc;

                #limit_conn   crawler  20;

                #location /status {
                #stub_status    on;
                #access_log     off;
                #}

                if (!-e $request_filename) {
                        rewrite ^(.*)$ /index.php?q=$1 last;
                }

                location ~ .*\.(php|php5)?$
                        {
                                fastcgi_pass  unix:/tmp/php-cgi.sock;
                                #fastcgi_pass  127.0.0.1:9000;
                                fastcgi_index index.php;
                                include fcgi.conf;
                        }

                location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
                        {
                                expires      30d;
                        }

                location ~ .*\.(js|css)?$
                        {
                                expires      12h;
                        }

                log_format  access1  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';
                access_log  /web/logs/access.log  access;
        }

改写成这样应该就OK了。
作者: cpuer    时间: 2009-11-1 11:40
原帖由 遍地阳光 于 2009-11-1 11:38 发表
能用吗?


可以。
作者: 遍地阳光    时间: 2009-11-1 11:41
标题: 回复 9# 的帖子
其实,我一直想typecho的,也是无法去掉固定连接里额。index.php
作者: gdtv    时间: 2009-11-1 11:43
标题: 回复 8# 的帖子
楼主的网址是在abc.com/blog 子目录下,规则可能要改改,不过我也不知怎么改
作者: 遍地阳光    时间: 2009-11-1 11:47
标题: 回复 11# 的帖子
我感觉也是要改的。

论坛放子目录要加 在.htaccess                RewriteBase /bbs
不知道,这次怎么弄。
作者: 遍地阳光    时间: 2009-11-1 11:57
标题: 回复 8# 的帖子
这个规则进去wordpress后台以后,点发布文章,编辑器出不来了,点固定连接也出不来,就是点左面的所有项目,右边都没有反应。
作者: gdtv    时间: 2009-11-1 11:57
标题: 回复 13# 的帖子
"点发布文章,编辑器出不来了"这个和固定链接没关系
后台操作和固定链接都没关系
作者: 遍地阳光    时间: 2009-11-1 11:59
标题: 回复 14# 的帖子
但是把那个规则换回去就出来了。
作者: cpuer    时间: 2009-11-1 12:14
原帖由 gdtv 于 2009-11-1 11:57 发表
"点发布文章,编辑器出不来了"这个和固定链接没关系
后台操作和固定链接都没关系


恩,这个跟伪静态没关系。
作者: cpuer    时间: 2009-11-1 12:16
原帖由 遍地阳光 于 2009-11-1 11:59 发表
但是把那个规则换回去就出来了。


你用 /usr/local/nginx/sbin/nginx -t 测试下nginx.conf 哪里有错误。
作者: 遍地阳光    时间: 2009-11-1 12:27
标题: 回复 17# 的帖子
现在调出来了,但固定连接还是有index.php,是不是跟子目录有关系。

我在wordpress.org.cn提问了,还没有回复。
作者: gdtv    时间: 2009-11-1 12:31
标题: 回复 18# 的帖子
看后台永久链接设置那里,有没有index.php
然后,看有没有.htaccess这个文件
虽然nginx用不上.htaccess,但WP可能会检测它,检测不到的话就给你加上index.php (只是猜测)
作者: 遍地阳光    时间: 2009-11-1 12:38
标题: 回复 19# 的帖子
如果把后台永久链接的那个index.php给去掉,就出现404.

blog根目录里没有。htaccess

.htaccess该怎么写?
作者: cpuer    时间: 2009-11-1 12:56
标题: 回复 20# 的帖子
nginx不支持.htaccess
作者: 遍地阳光    时间: 2009-11-1 13:48
标题: 回复 21# 的帖子
http://ipbfans.org/2009/01/nginx-wordpress-supercache-url-rewrite



他提到的pcre怎么装?
作者: cpuer    时间: 2009-11-1 13:53
标题: 回复 22# 的帖子
如果要安装supercache的话伪静态规则会不一样的。
作者: gdtv    时间: 2009-11-1 13:54
标题: 回复 22# 的帖子
你先用php探针看一下伪静态是不是支持了
作者: cpuer    时间: 2009-11-1 14:12
标题: 回复 24# 的帖子
nginx默认都支持伪静态的吧。
作者: 遍地阳光    时间: 2009-11-1 14:13
标题: 回复 25# 的帖子
在网上找到这样一句话。

location / :由于我的wordpress是直接运行在域名根目录下,所以这里就是/,如果你的目录运行在域名的子文件夹(如/blog/)下,那么这里就要变为 location /blog/

[ 本帖最后由 遍地阳光 于 2009-11-1 14:18 编辑 ]
作者: cpuer    时间: 2009-11-1 14:27
标题: 回复 26# 的帖子
伪静态已经生效的话就不用管这个了,

index.php是怎么回事? 给个链接看看。
作者: 遍地阳光    时间: 2009-11-1 14:36
http://www.xxx.com/blog/index.php/archives/123

就是这个样子,某人说在diagou随便放地址会被攻击的,所以我就不放了。
作者: cpuer    时间: 2009-11-1 14:55
标题: 回复 28# 的帖子
WordPress后台 Permalinks 是怎么设置得?
作者: 遍地阳光    时间: 2009-11-1 14:59
/%post_id%
设置成这样的。
我快要放弃了。就用动态的URL算了。折腾了两天了。
作者: cpuer    时间: 2009-11-1 15:01
那你把
                if (!-e $request_filename) {
                        rewrite ^(.*)$ /index.php?q=$1 last;
                }
改成
   location /blog/ {
                if (!-e $request_filename) {
                        rewrite ^(.*)$ /index.php?q=$1 last;
                }
    }

试下。
作者: 遍地阳光    时间: 2009-11-1 15:07
标题: 回复 31# 的帖子
还是404.



404 Not Found

--------------------------------------------------------------------------------

nginx/0.7.62
作者: cpuer    时间: 2009-11-1 15:13
标题: 回复 32# 的帖子
31楼做了新的修正,你再试下。
作者: 遍地阳光    时间: 2009-11-1 15:16
标题: 回复 33# 的帖子
还是不行。
作者: cpuer    时间: 2009-11-1 15:17
标题: 回复 34# 的帖子
/usr/local/nginx/sbin/nginx -t  测试结果?
作者: 遍地阳光    时间: 2009-11-1 15:18
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
[emerg]: open() "/web/logs/access.log" failed (2: No such file or directory)
configuration file /usr/local/nginx/conf/nginx.conf test failed


返回这个,什么意思?
作者: 34baidu    时间: 2009-11-1 15:21
标题: 回复 28# 的帖子
那我下次想攻击哪个站,直接在这放地址就行了
作者: cpuer    时间: 2009-11-1 15:25
原帖由 遍地阳光 于 2009-11-1 15:18 发表
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
[emerg]: open() "/web/logs/access.log" failed (2: No such file or directory)
configuration file /usr/local/nginx/conf/nginx.conf te ...


原来你没开日志,那用这个
server
{
  listen       80;
  server_name www.abc.com;
  index index.html index.htm index.php;
  root  /web/www/abc;

   location /blog/ {
                if (!-e $request_filename) {
                        rewrite ^(.*)$ /index.php?q=$1 last;
                }
    }

  location ~ .*\.(php|php5)?$
   {
    fastcgi_pass  unix:/tmp/php-cgi.sock;
    #fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    include fcgi.conf;
   }
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
   {
    expires      30d;
   }
  location ~ .*\.(js|css)?$
   {
    expires      12h;
   }
  access_log   off;
}

代替你的server段试试。
作者: 遍地阳光    时间: 2009-11-1 15:25
标题: 回复 37# 的帖子
代沟有很多牛人的。
作者: cpuer    时间: 2009-11-1 15:26
原帖由 34baidu 于 2009-11-1 15:21 发表
那我下次想攻击哪个站,直接在这放地址就行了


可惜xxx.com 不是楼主的域名,否则楼主大发了。
作者: 遍地阳光    时间: 2009-11-1 15:31
标题: 回复 40# 的帖子
嘿嘿,我早有防备的。

不过那个server段还是不行。
作者: myrte    时间: 2009-11-1 15:42
原帖由 遍地阳光 于 2009-11-1 14:59 发表
/%post_id%
设置成这样的。
我快要放弃了。就用动态的URL算了。折腾了两天了。

ww.wordpresschina.com
我的就是用nginx的啊,用的好好地啊,只是在后得在wp-admin后面加个/成wp-admin/
作者: 遍地阳光    时间: 2009-11-1 16:06
标题: 回复 42# 的帖子
我的是在子目录下面的。应该是这个原因的。
作者: cpuer    时间: 2009-11-1 16:23
标题: 回复 43# 的帖子
嗯,我只弄过根目录的。
作者: 遍地阳光    时间: 2009-11-1 16:30
标题: 回复 44# 的帖子
看来nginx还是没有Apache的适用性好啊。

希望nginx的普及化迅速点。这样我们菜鸟就能省心了。
作者: cpuer    时间: 2009-11-1 16:45
标题: 回复 45# 的帖子
nginx和lighttpd的普及之路还很长。
作者: flywyh    时间: 2009-11-1 22:08
原帖由 gdtv 于 2009-11-1 11:22 发表
我一直用这个rewrite规则,多简单:

                if (!-e $request_filename) {
                        rewrite ^(.*)$ /index.php?q=$1 last;
                }


正解,楼主的是网上流传最多的,但有问题。wordpress的rewrite原理超简单,就是找不到的文件夹或文件转给index.php处理。
作者: cpuer    时间: 2009-11-1 22:10
标题: 回复 47# 的帖子
伪静态规则都写入到index.php里面了其实
作者: flywyh    时间: 2009-11-1 22:12
原帖由 cpuer 于 2009-11-1 22:10 发表
伪静态规则都写入到index.php里面了其实


嗯,让用户轻松的方法。感觉lighttpd的规则比nginx的好写~
作者: gdtv    时间: 2009-11-1 22:20
原帖由 flywyh 于 2009-11-1 22:08 发表


正解,楼主的是网上流传最多的,但有问题。wordpress的rewrite原理超简单,就是找不到的文件夹或文件转给index.php处理。

这个有什么问题?
作者: cpuer    时间: 2009-11-1 22:31
标题: 回复 50# 的帖子
没有问题哈,WordPress程序的写法是这样而已。
作者: flywyh    时间: 2009-11-1 22:51
原帖由 cpuer 于 2009-11-1 22:31 发表
没有问题哈,WordPress程序的写法是这样而已。


有问题的,好象是比如你应经登录了,如果访问http://www.xxx.com/wp-admin/就能直接进后台,如果访问http://www.xxx.com/wp-admin就会让你再次登陆

网上有两种错误格式,其中一种问题是这个,另一个忘了。我现在不用nginx了,大家自己测试吧。
作者: cpuer    时间: 2009-11-1 22:51
标题: 回复 52# 的帖子
/和没有/在nginx下好像有解决办法吧。
作者: flywyh    时间: 2009-11-1 22:52
原帖由 cpuer 于 2009-11-1 22:51 发表
/和没有/在nginx下好像有解决办法吧。


正确的rewrite就没这个问题,不用刻意解决
作者: cpuer    时间: 2009-11-1 22:56
标题: 回复 54# 的帖子
学习了,WordPress官网就没公开发放过nginx的伪静态规则吧。
作者: flywyh    时间: 2009-11-1 23:00
没有,只有个人分享的。
  1.                 if (!-e $request_filename){
  2.                 rewrite (.*) /index.php last;
  3.                 }
复制代码
这是我自己以前用的,无错的,前提是在根目录
作者: cpuer    时间: 2009-11-1 23:08
标题: 回复 56# 的帖子
对,这个我也试过的,但是子目录的不知道怎么弄。
作者: 遍地阳光    时间: 2009-11-1 23:10
标题: 回复 56# 的帖子
有在子目录的方法没?
作者: flywyh    时间: 2009-11-1 23:11
原帖由 cpuer 于 2009-11-1 23:08 发表
对,这个我也试过的,但是子目录的不知道怎么弄。


/index.php 改成 /子目录/index.php
作者: 遍地阳光    时间: 2009-11-1 23:12
标题: 回复 59# 的帖子
我马上试试去。嘿嘿。
作者: flywyh    时间: 2009-11-1 23:15
原帖由 遍地阳光 于 2009-11-1 23:12 发表
我马上试试去。嘿嘿。


要注意这样根目录的错误路径也会被转到子目录
作者: 遍地阳光    时间: 2009-11-1 23:19
标题: 回复 61# 的帖子
这样还是不行。啊。


server
        {
                listen       80;
                server_name 我的域名;
                index index.html index.htm index.php;
                root  /home/www/我的目录;

                #limit_conn   crawler  20;

                #location /status {
                #stub_status    on;
                #access_log     off;
                #}

                if (!-e $request_filename) {
                        rewrite ^(.*)$ /blog/index.php?q=$1 last;
                }

                location ~ .*\.(php|php5)?$
                        {
                                fastcgi_pass  unix:/tmp/php-cgi.sock;
                                #fastcgi_pass  127.0.0.1:9000;
                                fastcgi_index index.php;
                                include fcgi.conf;
                        }

                location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
                        {
                                expires      30d;
                        }

                location ~ .*\.(js|css)?$
                        {
                                expires      12h;
                        }

                log_format  access1  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';
                access_log  /web/logs/access.log  access;
        }
作者: qwe123    时间: 2009-11-2 12:31
你们在干嘛呢
作者: rdpof    时间: 2009-11-2 12:40
忘了关键性问题,你在后台设置了没有?固定链接那里,截个图出来,再把你的WP地址发出来。
作者: cpuer    时间: 2009-11-2 13:13
原帖由 qwe123 于 2009-11-2 12:31 发表
你们在干嘛呢


在讨论nginx环境下,子目录安装WordPress怎么伪静态。
作者: corey    时间: 2010-1-26 17:55
这么久了,不知道楼主弄出来没有

我试过,这样是没问题的, 假设你的子目录是blog,

location /blog/ {
                if (!-e $request_filename) {
                        rewrite ^(.*)$ /blog/index.php?q=$1 last;
                }
}


作者: cpuer    时间: 2010-1-26 20:14
标题: 回复 66# 的帖子
确认这样可以么? 原来子目录这么弄。
作者: pmalc    时间: 2010-1-26 20:17
nginx还真有点麻烦
作者: corey    时间: 2010-1-26 21:04
标题: 回复 67# 的帖子
恩,确认可以的,可以看这里
http://www.lixing.org/wp-demo/google/

wp-demo是wp的子目录,google是/%postname%/
作者: cpuer    时间: 2010-1-26 21:20
标题: 回复 69# 的帖子
嘿嘿,学习了。




欢迎光临 全球主机交流论坛 (https://sunk.eu.org/) Powered by Discuz! X3.4