2016-11-22 128 views
0

我的改寫作品。NGINX - 重寫和錯誤404

另一方面,我的404錯誤重定向不再工作。

如果我添加到我的.php鏈接它返回我沒有文件。

同樣,當我把我的鏈接管理員/它把我的開幕式,菜單和copiryght。

舉例如果我把https://mon.domain.com/admin/加載我一頁,而我想我的404錯誤頁面。

我想什麼,如果頁面不存在,在我遇到我的錯誤無論如何404

你能幫助我嗎?

這裏是Nginx的配置:

upstream www { 
    server unix:/var/run/php5-fpm.sock; 
} 

server { 
    listen 80 default; 
    server_name no-impact.eu; 
     return 301 https://my.domain.com; 
} 
server { 
    listen 443 ssl; 
    server_name my.domain.com; 

    fastcgi_param HTTPS on; 
    ssl on; 
     ssl_certificate /etc/letsencrypt/live/my.domain.com/fullchain.pem; 
     ssl_certificate_key /etc/letsencrypt/live/my.domain.com/privkey.pem; 
     ssl_session_timeout 5m; 
     ssl_protocols SSLv2 SSLv3 TLSv1; 
     ssl_ciphers HIGH:!aNULL:!MD5; 
     ssl_prefer_server_ciphers on; 

    root /var/www/my.domain.com/; 
    index index.php; 

    error_page 400 401 402 403 404 500 502 503 504 /error.html; 

    location /.well-known/acme-challenge { 
     root /var/www/letsencrypt; 
    } 

    location = /error.html { 
     root /var/www/my.domain.com/error/; 
     index index.html; 
    } 

    location/{ 
     index index.php index.html; 
     try_files $uri $uri/ @rewrite; 
    } 

    location @rewrite { 
     rewrite ^/([\w-]+)-page-(\d+)$ /index.php?id=$1&page=$2 last; 
     rewrite ^/([\w-]+)-(\d+)$ /index.php?id=$1&id_tutoriel=$2 last; 
     rewrite ^/(.*)$ /index.php?id=$1 last; 
    } 


    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; 
    } 

} 

+0

嘗試將'root /var/www/my.domain.com/;'移動到服務器塊內的位置/ {...}塊中。 – AaronDanielson

+0

我只是嘗試,但它使我工作的網頁無處不在的錯誤 –

回答

0

這裏的問題是,你重寫告訴nginx一切重定向到後端,所以nginx的不檢測404本身。您的後端然後處理請求併發送一個404,nginx直接發送回客戶端。

爲了讓nginx攔截404並顯示自己的錯誤頁面,您需要將指令fastcgi_intercept_errors on;添加到您的.php位置。

+0

感謝所有的幫助,我已經解決了這個問題。錯誤出現在塊的位置的第三個正則表達式中,'(。*)'替換了其所有的字符。我已經用'([\ w - ] +)替換了我的表達式,這是工作。 –