Nginx
url重寫,nginx拋出404錯誤,錯誤日誌中沒有任何內容
下面的重寫工作正常:
rewrite ^/city/restaurants$ /city/listings/restaurants permanent;
但這不起作用
rewrite ^/city/restaurants$ /city/listings/restaurants last; rewrite ^/city/restaurants$ /city/listings/restaurants break;
我究竟做錯了什麼?
在整個 nginx 伺服器塊下方
server { listen 80 default backlog=1024; server_name mydomain.com; client_max_body_size 20M; charset utf-8; keepalive_timeout 50; access_log /var/log/access_log main; error_log /var/log/error_log info; root /var/www/; index index.php index.phtml index.html; autoindex on; location ~ \..*/*\.php$ { return 403; } location ~^/sites/.*/private/{ return 403; } location ~^/sites/.*/files/* { try_files $uri @rewrite; } location ~ (^|/)\. { return 403; } location / { rewrite ^/city/restaurants$ /city/listings/restaurants last; location ~* \.php$ { include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_pass 127.0.0.1:9000; #try_files $uri @rewrite; } try_files $uri @rewrite; } location @rewrite { rewrite ^ /index.php; } location ~* \.(?:ico|css|js|gif|jpg|jpeg|png)$ { try_files $uri $uri/; expires 30d; } }
首先,將密鑰重寫移出
location
塊到封閉server
塊中。這將簡化您的邏輯。接下來,啟用重寫調試日誌以確認您獲得的 404 是來自原始 URL,還是來自重寫的 URL。
最後,如果仍未找到根本原因,請為 Nginx啟用正常調試日誌記錄:
error_log /path/to/log debug;