2010-06-25 987 views
5

每當發生403錯誤時,我都試圖在/temp/www/error403.html中顯示錯誤頁面。用nginx返回自定義403錯誤頁面

這應該是無論何時用戶試圖通過https(ssl)訪問站點,並且它的IP位於blovkips.conf文件中,但目前它仍顯示nginx的默認錯誤頁面。 我有我的其他服務器(沒有任何阻止)相同的代碼,它的工作原理。

它阻止IP訪問自定義403頁面嗎? 如果是這樣,我如何才能使它工作?

server { 
    # ssl 
    listen    443; 
    ssl     on; 
    ssl_certificate  /etc/nginx/ssl/site.in.crt; 
    ssl_certificate_key /etc/nginx/ssl/site.in.key; 
    keepalive_timeout 70; 

    server_name localhost; 


    location/{ 
      root /temp/www; 
      index index.html index.htm; 
} 

# redirect server error pages to the static page 
error_page 403 /error403.html; 
# location = /error403.html { 
#   root /temp/www; 
# } 

    # add trailing slash if missing 
    if (-f $document_root/$host$uri) { 
      rewrite ^(.*[^/])$ $1/ permanent; 
    }  

    # list of IPs to block 
    include blockips.conf; 
} 

編輯: 修正error_page代碼從504到403,但我仍然有同樣的問題

回答

0

它看起來像有一個噓,噓在列出的配置,因爲它是隻發送的出錯代碼503(「服務不可用」)的自定義頁面,所以403(「禁止」),你可能想使用:

error_page 403 /error403.html 
+0

(這裏我假定blockips.conf文件是有效的,每行都像'deny 1.2.3.4;'。) – ewall 2010-06-30 19:36:15

+0

是封鎖。據我所知,conf是正確的,我只有這個沒有註釋:否認所有; (用於測試) – Mint 2010-07-01 00:02:12

+0

好吧,我編輯了配置文件403不503現在,做了重新啓動,我仍然得到默認的'403 Forbidden nginx'任何其他想法? – Mint 2010-07-01 00:08:17

1

問題可能是,您正在嘗試從禁止訪問的網絡服務器向服務器發送403「禁止」錯誤。 Nginx將error_page指令視爲內部重定向。所以它試圖服務器https://example.com/error403.html這也是禁止的。

所以,你需要做的錯誤頁面未送達了HTTPS的是這樣的:

error_page 403 http://example.com/error403.html 

或添加必要的「允許訪問」選項的錯誤頁面路徑的位置。測試的方法是直接訪問/error403.html頁面。如果你不能這樣訪問,當有人得到實際的403錯誤時,它不會工作。

0

我有同樣的問題...重點是,我已經在服務器上下文級別(或虛擬主機級別,如果你願意)實施IP白名單,所以每個地點都會有這個(basicaly /403.html won 「T可訪問):

server { 
    listen  *:443 ssl; 
    server_name mydomain.com ; 
    error_page 403 /403.html; 
    ..... 
    if ($exclusion = 0) { return 403; } #implemented in another conf.d files (see below) 
    location ~ \.php$ { 
    root   /var/www/vhosts/mydomain.com/httpdocs; 
    include  /etc/nginx/fastcgi_par 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_connect_timeout 3m; 
    fastcgi_read_timeout 3m; 
    fastcgi_send_timeout 3m; 
    } 
    location /403.html { 
    root  /usr/share/nginx/html; 
    allow all; 
    } 

    ... 
} 

排除conf.d文件樣本:

geo $exclusion { 
    default 0; 
    10.0.0.0/8 Local network 
    80.23.120.23 Some_ip 
    ... 
} 

爲了解決這個問題只需做你的位置等級復原403(上下文):

server { 
    listen  *:443 ssl; 
    server_name mydomain.com ; 
    error_page 403 /403.html; 
    ..... 
    location ~ \.php$ { 
    if ($exclusion = 0) { return 403; } 
    root   /var/www/vhosts/mydomain.com/httpdocs; 
    include  /etc/nginx/fastcgi_par 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_connect_timeout 3m; 
    fastcgi_read_timeout 3m; 
    fastcgi_send_timeout 3m; 
    } 
    location /403.html { 
    root  /usr/share/nginx/html; 
    allow all; 
    } 

    ... 
} 

適合我。