2011-05-27 64 views
21

我已經嘗試了很多不同的東西。我現在的觀點是這樣的:Nginx - wordpress在子目錄中,應該傳遞什麼數據?

location ^~ /wordpress { 
    alias /var/www/example.com/wordpress; 
    index index.php index.html index.htm; 
    try_files $uri $uri/ /wordpress/index.php; 

    location ~ \.php$ { 
     include fastcgi_params; 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_split_path_info ^(/wordpress)(/.*)$; 
     fastcgi_param SCRIPT_FILENAME /var/www/example.com/wordpress/index.php; 
     fastcgi_param PATH_INFO $fastcgi_path_info; 
    } 
} 

現在,所有資源,據我所知(圖像等)加載正確。並且http://www.example.com/wordpress加載wordpress,但是顯示「找不到頁面」的頁面。 (雖然Wordpress正在使用)。如果我嘗試任何帖子的網址,我會得到相同的結果,「頁面未找到」。所以我知道問題在於wordpress沒有獲取有關路徑或其他內容的數據。另一個潛在的問題是,如果我運行example.com/wp-admin.php那麼它仍然會運行index.php

什麼數據需要傳遞?這裏可能會出現什麼問題?

回答

39

由於您的位置別名匹配,您應該只使用root。另外,不是所有都是通過wordpress afaik上的index.php路由的。另外,除非你知道你需要路徑信息,否則你可能不會。我想你想要的東西,如:

location @wp { 
    rewrite ^/wordpress(.*) /wordpress/index.php?q=$1; 
} 

location ^~ /wordpress { 
    root /var/www/example.com; 
    index index.php index.html index.htm; 
    try_files $uri $uri/ @wp; 

    location ~ \.php$ { 
     include fastcgi_params; 
     fastcgi_param SCRIPT_FILENAME $request_filename; 
     fastcgi_pass 127.0.0.1:9000; 
    } 
} 

,或者如果你真的需要路徑信息(網址看起來像/wordpress/index.php/foo/bar):

location ^~ /wordpress { 
    root /var/www/example.com; 
    index index.php index.html index.htm; 
    try_files $uri $uri/ /wordpress/index.php; 

    location ~ \.php { 
     fastcgi_split_path_info ^(.*\.php)(.*)$; 
     include fastcgi_params; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_param PATH_INFO $fastcgi_path_info; 
     fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; 
     fastcgi_pass 127.0.0.1:9000; 
    } 
} 

編輯:更新後的第一服務器{}從URI剝離初始/ WordPress的,並通過其餘部分爲q PARAM

EDIT2:命名位置只適用在服務器級

+0

我嘗試(你的第一個),但我一直在404找不到wordpress頁面。這可能與我將博客從不同的域移動到具有子目錄的域相關。 – Matthew 2011-05-27 18:09:53

+0

我想可能wordpress需要最初/ wordpress剝離。編輯第一臺服務器來做到這一點。 – kolbyjack 2011-05-27 19:48:37

+4

這就是確定的答案!我已經使用'location/wordpress'代替'location ^〜/ wordpress'和'alias'代替'root'的第一個解決方案。 – micred 2013-11-28 08:30:06

12

哥們,這將在的一個子目錄工作了WordPress的博客magento根文件夾!

server { 
listen 80; 
server_name my-site.co.uk; 
rewrite/$scheme://www.$host$request_uri permanent; ## Forcibly prepend a www 
} 

server { 
listen 80 default; 
client_max_body_size 8M; 
## SSL directives might go here 
server_name www.my-site.co.uk; ## Domain is here twice so server_name_in_redirect will favour the www 
root /var/www/my-site/magento; 

location/{ 
    index index.html index.php; ## Allow a static html file to be shown first 
    try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler 
    expires 30d; ## Assume all files are cachable 
} 

location /wordpress { 
      index index.php index.html index.htm; 
     try_files $uri $uri/ /wordpress/index.php; 
     } 

## These locations would be hidden by .htaccess normally 
location ^~ /app/    { deny all; } 
location ^~ /includes/   { deny all; } 
location ^~ /lib/    { deny all; } 
location ^~ /media/downloadable/ { deny all; } 
location ^~ /pkginfo/   { deny all; } 
location ^~ /report/config.xml { deny all; } 
location ^~ /var/    { deny all; } 

location /var/export/ { ## Allow admins only to view export folder 
    auth_basic   "Restricted"; ## Message shown in login window 
    auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword 
    autoindex   on; 
} 

location /. { ## Disable .htaccess and other hidden files 
    return 404; 
} 


location @handler { ## Magento uses a common front handler 
    rewrite//index.php; 
} 

location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler 
    rewrite ^(.*.php)/ $1 last; 
} 

location ~ .php$ { ## Execute PHP scripts 
    if (!-e $request_filename) { rewrite//index.php last; } ## Catch 404s that try_files miss 

    expires  off; ## Do not cache dynamic content 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    fastcgi_param HTTPS $fastcgi_https; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores 
    fastcgi_param MAGE_RUN_TYPE store; 
    include  fastcgi_params; ## See /etc/nginx/fastcgi_params 
} 

}

+0

如果任何人想要的核心配置文件我用於Nginx的這個網站配置只是讓我知道。 – 2013-03-26 15:17:48

+0

適合我,即時消息不使用Magento,但該塊爲wordpress是有幫助的。 thx – risnandar 2013-08-05 16:10:16

+0

豎起大拇指!非常簡單直接,即wordpress部分,併爲我的網站完美工作。我發現codex.wordress.com上的例子非常複雜! – 2014-07-17 20:31:54

1

我有同樣的問題,這是固定的對我來說:爲您的網站

  1. 打開NGINX配置文件。在服務器內部塊,路徑添加到您的根目錄下,並設置文件的優先順序:

    root /mnt/www/www.domainname.com; 
    index index.php index.html index.htm; 
    
  2. 創建一個空的位置塊所有其他位置的塊

    location /latest { 
    # Nothing in here; this is to avoid redirecting for this location 
    } 
    
  3. 推薦您的位置/塊的根目錄並添加重定向,使其看起來像這樣:

    location/{ 
    # root /mnt/www/www.domainname.com; 
    index index.php index.html index.htm; 
    rewrite ^/(.*)$ http://www.domainname.com/latest/$1 redirect; 
    } 
    
  4. 確保您的位置〜.PHP $塊指向其根

    root /mnt/www/www.domainname.com; 
    

這個固定爲我。

相關問題