2012-08-09 92 views
1

我試圖設置動態404頁,以便我可以保留缺少的內容的URL,在404頁面上顯示它,並保持我的網站的模板一致。Nginx 404動態PHP與重寫

這裏是我的地盤的conf:

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

    client_max_body_size 1024M; 
    client_body_buffer_size 512M; 

    rewrite ^/([a-zA-Z0-9-_]+)$ /profile.php?url=$1 last; 

    root /var/www/html/mysite; 
    error_page 404 /404.php 

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

    location/{ 
     index index.php index.html index.htm; 
    } 

    location ~ \.php$ { 
     fastcgi_pass mysite_fast_cgi; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME /var/www/html/mysite$fastcgi_script_name; 
     include  fastcgi_params; 
    } 

    location ~ /\.ht { 
     deny all; 
    } 

    location = /404.php { 
     internal; 
    } 
} 

這僅僅是爲默認Nginx的404頁。

感謝您的幫助!

+0

你忘記我只是打周圍的各種設置和似乎沒有什麼工作,你/404.php位置 – CyberDem0n 2012-08-09 14:37:04

+0

proxy_pass。 我累了proxy_pass http://mysite.com/404.php,http:// mysite_fast_cgi,我也嘗試了.php $ location塊的fastcgi_pass設置。 – grandcameo 2012-08-09 15:18:13

回答

1

你試過error_page 404 = /404.php;

下面是官方nginx的文檔的報價:

If an error response is processed by a proxied server, or 
a FastCGI server, and the server may return different response 
codes (e.g., 200, 302, 401 or 404), it is possible to respond 
with a returned code: 

    error_page 404 = /404.php; 
+0

我接受這個,因爲我以前就是這樣的(甚至試過「= 200/404.php」,但是它沒有工作的原因是因爲我的404.php頁面是通過返回一個404頭文件而開始的 – grandcameo 2012-08-09 19:19:45

+0

error_page 404 = 200 /404.php ;? – CyberDem0n 2012-08-10 03:15:37