2014-03-04 94 views
2

首先,首次使用nginx的用戶。所以,我仍然在學習Apache和nginx的差異。nginx配置默認錯誤頁面

我有一個nginx的股票安裝。 (apt-get install nginx-full)我修改了在'/ etc/nginx/sites-enabled/default'找到的默認配置。但是,錯誤頁面不起作用。我的docroot是/ server/www,我的錯誤頁面位於目錄/ server/errors /中。以下是我的配置。

server { 
    listen 80 default_server; 
    listen [::]:80 default_server ipv6only=on; 

    root /server/www; 
    index index.html; 

    server_name website.com; 

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

    error_page 403 404 405 /40x.html; 
    location /40x.html { 
     root /server/errors; 
     internal; 
    } 

    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
     root /server/errors; 
     internal; 
    } 

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

    location ~ /\.ht { 
     deny all; 
    } 
} 

所有應該生成403頁或404頁的頁面,只需加載index.html文件即可。我相信有些事情可能發生在500個錯誤,但是,這有點難以產生。

另外,如果它是相關的,我將錯誤頁面移到docroot上面,但他們之前沒有工作。我做了這個舉動,因爲「內部」標誌似乎並沒有像文檔聲明那樣使頁面成爲內部頁面,因爲我仍然可以直接訪問它們。

任何建議/你可以給的幫助將是偉大的!

+0

我必須問,你是否在你改變設置時重新加載nginx? –

+0

http://wiki.nginx.org/HttpCoreModule - 請閱讀'訂購'部分。 – Danack

+0

是的,我在每次更改配置後都重新啓動了nginx。 –

回答

2

錯誤問題與位置/有/index.html的最終值有關。本質上,nginx首先嚐試將uri作爲文件,然後作爲目錄,然後恢復爲index.html。相反,我希望它返回一個404.所以我改變它到下面,現在它的工作。

location/{ 
    try_files $uri $uri/ =404; 
}