2014-01-20 94 views
1

我已經安裝了nginx,我嘗試在其上運行wordpress。 一切工作正常,除了永久鏈接。nginx&wordpress - 配置永久鏈接不起作用;下載php文件,而不是

這裏是虛擬主機文件我使用:

server { 
listen 123456:80; 
server_name my-domain.com; 

if ($host ~* www\.(.*)) { 
    set $wwwless $1; 
    rewrite ^(.*)$ $scheme://$wwwless$1 permanent; 
} 

root /var/www/my-folder; 

index index.php; 

    location/{ 
      try_files $uri $uri/ /index.php?q=$uri&$args; 
    } 

    location ~ \.php$ { 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_index index.php; 
     include fastcgi_params; 
    } 
} 

(我已經更換了關鍵數據在上面的代碼與my-domain.com,我的文件夾和IP 123456)

index.php,管理面板和使用標準鏈接(... /?p = 123)工作finde。如果我啓用了一些固定鏈接,index.php和管理面板仍然可以使用。但是,如果我嘗試打開W​​ordPress博客的另一個網站,我的瀏覽器下載的index.php :(

+0

我可以通過將以下內容添加到location〜.php $ { fastcgi_param SCRIPT_FILENAME $ document_root/$ fastcgi_script_name; 現在我可以訪問博客的其他網站。但是,如果我嘗試訪問博客文章,如http://my-domain.com/1/hello-world/,我仍然會下載index.php。 :/ – user3216381

+0

解決最後一個問題的方法是在永久鏈接中使用構建,而不是自定義構建。 – user3216381

回答

0

嘗試像這樣的.PHP位置配置:

location ~ \.php$ { 
    include  /etc/nginx/fastcgi_params; 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
} 
0

,這裏是我的wordpress的配置修改適合你。

server { # the redirecting from www to non-www 
    server_name www.example.com; 
    return 301 $scheme://example.com$request_uri$is_args$query_string; 
} 

server { 
    listen 80; 
    server_name example.com; 
    root /path/to/root; 
    # make sure the directory /var/log/nginx exists 
    access_log /var/log/nginx/wordpress_access.log; 
    error_log /var/log/nginx/wordpress_error.log; 
    index index.php; 
    location/{ 
    try_files $uri /index.php$request_uri$is_args$query_string; 
    } 
    location ~ \.php { 
    include fastcgi_params; 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    } 
    location ~ /\.ht { # avoid downloading htaccess, htpasswd, etc files 
    deny all; 
    } 
} 
0

你可以試試這個虛擬主機文件

server { 
    listen 80; 
    server_name www.example.com example.com; 
    root /var/www/www.example.com/web; 
    if ($http_host != "www.example.com") { 
      rewrite^http://www.example.com$request_uri permanent; 
    } 
    index index.php index.html; 
    location = /favicon.ico { 
      log_not_found off; 
      access_log off; 
    } 
    location = /robots.txt { 
      allow all; 
      log_not_found off; 
      access_log off; 
    } 
    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). 
    location ~ /\. { 
      deny all; 
      access_log off; 
      log_not_found off; 
    } 
    location/{ 
      try_files $uri $uri/ /index.php?$args; 
    } 
    # Add trailing slash to */wp-admin requests. 
    rewrite /wp-admin$ $scheme://$host$uri/ permanent; 
    location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ { 
      expires max; 
      log_not_found off; 
    } 
    location ~ \.php$ { 
      try_files $uri =404; 
      include /etc/nginx/fastcgi_params; 
      fastcgi_pass 127.0.0.1:9000; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 

}