2013-12-15 90 views
0

我有一個wordpress安裝在/ var/www/blog中。我想通過www.domain.com來訪問它,所以我創建包含domain.com Nginx的配置文件:nginx配置爲wordpress

server { 
    listen 80; 

    server_name domain.com www.domain.com; 

    root /var/www/blog; 
    index index.php index.html index.htm; 

    access_log /var/log/nginx/www.domain.com.access.log; 
    error_log /var/log/nginx/www.domain.com.error.log; 

    location/{ 
      try_files $uri $uri/ /index.php; 
    } 

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

但是當我打開www.domain.com時,CSS/JS文件不加載。在我的error.log我得到:

2013/12/15 12:47:29 [error] 19562#0: *9 open() "/var/www/blog/blog/wp-content/themes/twentytwelve/style.css" failed (2: No such file or directory), client: yy.yy.yy.yy, server: domain.com, request: "GET /blog/wp-content/themes/twentytwelve/style.css?ver=3.8 HTTP/1.1", host: "xx.xx.xx.xx", referrer: "http://xx.xx.xx.xx/" 
2013/12/15 12:47:29 [error] 19562#0: *11 open() "/var/www/blog/blog/wp-content/themes/twentytwelve/js/navigation.js" failed (2: No such file or directory), client: yy.yy.yy.yy, server: domain.com, request: "GET /blog/wp-content/themes/twentytwelve/js/navigation.js?ver=1.0 HTTP/1.1", host: "xx.xx.xx.xx", referrer: "http://xx.xx.xx.xx/" 

我不明白爲什麼「/ blog /」被添加到鏈接中。 感謝您的幫助!

回答

0

這是我改變你的配置,這幾乎是正確

server { 
    listen 80; 
    server_name domain.com www.domain.com; 

    root /var/www/blog; 
    index index.php index.html index.htm; 

    access_log /var/log/nginx/www.domain.com.access.log; 
    error_log /var/log/nginx/www.domain.com.error.log; 

    location/{ 
     try_files $uri $uri/ /index.php$request_uri; #change here 
    } 

    location ~ \.php$ { 
     # removed unnecessary lines. 
     include fastcgi_params; 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
    } 
} 
+0

我想你的配置,但我得到了'2013年12月15日十三時34分57秒[錯誤] 21982#0:* 39或改寫內部重定向週期,同時在內部重定向到「/index.php/blog/wp-content/themes/twentytwelve/style.css」,客戶端:yy.yy.yy.yy,服務器:domain.com,請求:「GET /博客/wp-content/themes/twentytwelve/style.css?ver=3.8 HTTP/1.1「,主機:」xx.xx.xx.xx「,引薦來源:」http://www.domain.com/「'。所以我在/index.php和$ request_uri之間加了一個空格。現在css/js已經成功加載,但wordpress的顯示仍然沒有顯示,當我點擊一個鏈接時,頁面被下載。 – kdelemme

+0

爲什麼它試圖通過index.php訪問CSS?不應該是'/ blog/wp-content/themes/twentytwelve/style.css'沒有'index.php' –

+0

是的,它應該但我不知道爲什麼。 – kdelemme