VPS侦探论坛

 找回密码
 注册
查看: 6371|回复: 7

求助,搞不定二级目录下Wordpress的伪静态,求军哥指点迷津,

[复制链接]
发表于 2013-12-6 22:26:05 | 显示全部楼层 |阅读模式

如何,试过了好多方法,实在不知道二级目录下的Wordpress博客的伪静态处理方法。把配置文件贴出来,求大神指点一下,看问题出在哪里?

可以正常访问xxx.com/blog/,但是下面的文章就会出现404错误


我的网站目录:
/home/wwwroot/xxx:

WP Blog目录:
/home/wwwroot/xxx/blog


Nginx.conf文件
  1. user  www www;

  2. worker_processes 1;

  3. error_log  /home/wwwlogs/nginx_error.log  crit;

  4. pid        /usr/local/nginx/logs/nginx.pid;

  5. #Specifies the value for maximum file descriptors that can be opened by this process.
  6. worker_rlimit_nofile 51200;

  7. events
  8.         {
  9.                 use epoll;
  10.                 worker_connections 51200;
  11.         }

  12. http
  13.         {
  14.                 include       mime.types;
  15.                 default_type  application/octet-stream;

  16.                 server_names_hash_bucket_size 128;
  17.                 client_header_buffer_size 32k;
  18.                 large_client_header_buffers 4 32k;
  19.                 client_max_body_size 50m;

  20.                 sendfile on;
  21.                 tcp_nopush     on;

  22.                 keepalive_timeout 60;

  23.                 tcp_nodelay on;

  24.                 fastcgi_connect_timeout 300;
  25.                 fastcgi_send_timeout 300;
  26.                 fastcgi_read_timeout 300;
  27.                 fastcgi_buffer_size 64k;
  28.                 fastcgi_buffers 4 64k;
  29.                 fastcgi_busy_buffers_size 128k;
  30.                 fastcgi_temp_file_write_size 256k;

  31.                 gzip on;
  32.                 gzip_min_length  1k;
  33.                 gzip_buffers     4 16k;
  34.                 gzip_http_version 1.0;
  35.                 gzip_comp_level 2;
  36.                 gzip_types       text/plain application/x-javascript text/css application/xml;
  37.                 gzip_vary on;
  38.                 gzip_proxied        expired no-cache no-store private auth;
  39.                 gzip_disable        "MSIE [1-6]\.";

  40.                 #limit_zone  crawler  $binary_remote_addr  10m;

  41.                 server_tokens off;
  42.                 #log format
  43.                 log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
  44.              '$status $body_bytes_sent "$http_referer" '
  45.              '"$http_user_agent" $http_x_forwarded_for';

  46. server
  47.         {
  48.                 listen       80;
  49.                 server_name www.xxx.com;
  50.                 index index.html index.htm index.php;
  51.                 root  /home/wwwroot/xxx;

  52. #include wordpress.conf;

  53.                 location ~ .*\.(php|php5)?$
  54.                         {
  55.                                 try_files $uri =404;
  56.                                 fastcgi_pass  unix:/tmp/php-cgi.sock;
  57.                                 fastcgi_index index.php;
  58.                                 include fcgi.conf;
  59.                         }

  60.                 location /status {
  61.                         stub_status on;
  62.                         access_log   off;
  63.                 }

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

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

  72.                 access_log  /home/wwwlogs/access.log  access;
  73.         }
  74. include vhost/*.conf;
  75. }
复制代码
vhost/xxx.conf文件:
  1. server
  2.         {
  3.                 listen       80;
  4.                 server_name www.xxx.com xxx.com;
  5.                 index index.html index.htm index.php default.html default.htm default.php;
  6.                 root  /home/wwwroot/xxx;

  7.                 include wp2.conf;
  8.                 location ~ .*\.(php|php5)?$
  9.                         {
  10.                                 try_files $uri =404;
  11.                                 fastcgi_pass  unix:/tmp/php-cgi.sock;
  12.                                 fastcgi_index index.php;
  13.                                 include fcgi.conf;
  14.                         }

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

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

  23.                 access_log off;
  24.         }
复制代码
WP2.conf文件:
  1. location /blog/ {      
  2.     if (-f $request_filename/index.html){      
  3.     rewrite (.*) $1/index.html break;      
  4.     }      
  5.     if (-f $request_filename/index.php){      
  6.     rewrite (.*) $1/index.php;      
  7.     }      
  8.     if (!-f $request_filename){      
  9.     rewrite (.*) /blog/index.php;      
  10.     }      
  11. }
复制代码

以上失败,求解决方法!
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2013-12-6 22:29:23 | 显示全部楼层


期间试过一下N种方法,均以失败告终:
1. 方法1
  1. location / {
  2. rewrite ^/blog/wp-admin$ /blog/wp-admin/ permanent;
  3.         if (-f $request_filename/index.html){
  4.                 rewrite ^/blog/(.*) /blog/$1/index.html break;
  5.         }
  6.         if (-f $request_filename/index.php){
  7.                 rewrite ^/blog/(.*) /blog/$1/index.php;
  8.         }
  9.         if (!-f $request_filename){
  10.                 rewrite ^/blog/(.*) /blog/index.php;
  11.         }
  12. }
复制代码



2. 方法2:
  1. location /blog/{
  2. rewrite ^/wp-admin$ /wp-admin/ permanent;
  3.         if (-f $request_filename/index.html){
  4.                 rewrite (.*) $1/index.html break;
  5.         }
  6.         if (-f $request_filename/index.php){
  7.                 rewrite (.*) $1/index.php;
  8.         }
  9.         if (!-f $request_filename){
  10.                 rewrite (.*) /blog/index.php;
  11.         }
  12. }
复制代码



3. 方法3:
  1.        location /blog/ {
  2.                         try_files $uri $uri/ /blog/index.php?q=$uri&$args;
  3.         }
复制代码
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2013-12-9 22:40:29 | 显示全部楼层

顶起来,继续求答案
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2013-12-10 09:12:20 | 显示全部楼层



wp2.conf 的就是没问题的
你自己看看wp2.conf的源文件是什么,你改错了
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2014-1-13 10:23:04 | 显示全部楼层

回复 4# 的帖子


军哥,没错啊,实在找不到出错原因

军哥运维代购:http://shop63846532.taobao.com/

发表于 2014-1-13 14:41:53 | 显示全部楼层

wp2.conf原文件如下:
  1. location /wp {
  2. if (-f $request_filename/index.php) {
  3. rewrite (.*) $1/index.php;
  4. }
  5. if (!-f $request_filename){
  6. rewrite ^/wp/(.*)$ /wp/index.php;
  7. }
  8. }
复制代码


wp替换为对应的目录,你自己看看你怎么改的对比一下就知道了
 楼主| 发表于 2014-1-16 23:15:30 | 显示全部楼层

回复 6# 的帖子


换了,还是没用....
仍然是404
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2014-1-16 23:15:34 | 显示全部楼层

回复 6# 的帖子


  1. server { listen 80; server_name www.xxxx.com xxx.com; index index.html index.htm index.php default.html default.htm default.php;
  2. root /home/wwwroot/xxxx;
  3. include wp2.conf; location ~ .*\.(php|php5)?$ { try_files $uri =404; fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } access_log off; }
复制代码
  1. location /blog { if (-f $request_filename/index.php) { rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite ^/blog/(.*)$ /blog/index.php; } }
复制代码
军哥,你看
换了,还是没用....
仍然是404


[ 本帖最后由 Frank 于 2014-1-16 23:20 编辑 ]
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-25 09:36 , Processed in 0.027531 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表