2013-08-07 18 views
6

我在一個新的EC2實例上設置我的博客,因爲當前託管它的服務器上的一個站點正在被DDoSed。 我在nginx上遇到了一些麻煩,因爲我可以在索引上看到所有的頁面,但在索引上看到403,或者在頁面上看到索引,但看到404(取決於我使用的配置)403用nginx禁用wordpress索引時,其餘頁面正常工作

這是我的nginx的配置:

server { 
    listen  80; 

    server_name www.test.com; 
    server_name test.com; 
    root /www/blog; 

    include conf.d/wordpress/simple.conf; 
} 

而且simple.conf:

location = /favicon.ico { 
      log_not_found off; 
      access_log off; 
    } 

    location = /robots.txt { 
      allow all; 
      log_not_found off; 
      access_log off; 
    } 

    location/{ 
      # This is cool because no php is touched for static content. 
      # include the "?$args" part so non-default permalinks doesn't break when using query string 
      try_files $uri $uri/ /index.php?$args; 
    } 

    location ~ \.php$ { 
      #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini 
      include fastcgi.conf; 
      fastcgi_intercept_errors on; 
      fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; 
    } 

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { 
      expires max; 
      log_not_found off; 
    } 

如果我改變try_files $ URI $ URI//index.php?$args;以指數的index.php,頭版將正常工作,其餘的將是404。如果我離開它這樣,頭版是403

這裏的錯誤日誌:

2013/08/07 19:19:41 [error] 25333#0: *1 directory index of "/www/blog/" is forbidden, client: 64.129.X.X, server: test.com, request: "GET/HTTP/1.1", host: "www.test.com" 

那nginx用戶目錄爲755:

drwxr-xr-x 6 nginx nginx 4096 Aug 7 18:42 blog 

有沒有什麼明顯的我做錯了?

謝謝!

回答

17

添加index index.php;在服務器塊,如果它不工作,那麼你需要刪除$uri/因爲你不想做一個autoindex on


編輯:只注意到你已經想通了你的問題,所以我會添加的理由背後,爲什麼你需要 autoindex on;的原因是因爲沒有它的nginx將遵循 try_files規則,

  1. 檢查是否有一個名爲/的文件,當然它失敗了。
  2. 檢查是否有一個名爲/的目錄(通過添加root會= /www/blog/),此檢查將成功,因此它會嘗試列出文件夾的內容。
  3. 由於您沒有指定autoindex on;所以默認情況下nginx應該禁止目錄列表,因此它會返回一個403禁止的錯誤。
  4. 該網站的其他工作得很好,因爲它失敗$uri/測試或沒有達到它,因爲你可能沒有一個叫image.jpgstylesheet.css文件夾等
0

看來你不允許將參數發送到CMS,所以這不會顯示這個會從數據庫中帶來信息並將您重定向到403頁的uris。

+0

不知道你的意思是有什麼,我通過?$ args發送參數? –

1

看起來像我所需要的inded index.php文件在服務器{}定義,而不是在位置{}

+0

大聲笑剛剛意識到你回答了它,我回答後,沒有注意到,我猜我會編輯我的答案來解釋爲什麼。 –

相關問題