Nginx尝试在重写不存在的URL时下载文件

所有对不存在文件的请求都应该被重写到index.php?name = $ 1

所有其他请求应该照常处理。

有了这个服务器块,服务器正试图下载所有不存在的url:

server { server_name www.domain.com; rewrite ^(.*) http://domain.com$1 permanent; } server { listen 80; server_name domain.com; client_max_body_size 500M; index index.php index.html index.htm; root /home/username/public_html; location ~ /\.ht { deny all; } location ~ \.php$ { try_files $uri = 404; fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi_params; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9002; } location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { access_log off; log_not_found off; expires max; } location /plg { } location / { if (!-f $request_filename){ rewrite ^(.*)$ /index.php?name=$1 break; } } } 

我已经检查,看看我的default_type =文本/ HTML而不是八位字节stream,不知道是什么交易。

你应该读如果是邪恶的 ,下面应该做的伎俩。 如果您有关于某些街区的问题留下评论,我会解释。

 server { server_name www.domain.com; return 301 $scheme://domain.com$request_uri; } server { listen 80; server_name domain.com; client_max_body_size 500M; index index.php index.html index.htm; root /home/username/public_html; location / { # Hide ALL hidden files location ~* /\. { deny all; } # Directly deliver, good. location ~* ^.+\.(ogg|ogv|svgz?|eot|otf|woff|mp4|ttf|rss|atom|jpe?g|gif|png|ico|zip|t?gz|rar|bz2|doc|xls|exe|ppt|tar|midi?|wav|bmp|rtf)$ { access_log off; log_not_found off; expires max; } # Process PHP files, try_files protects us. location ~* \.php$ { # You only need this if you want to process requests like: # /index.php/foo/bar # Which is dangerous! fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi_params; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_pass 127.0.0.1:9002; try_files $uri =404; } try_files $uri @file-missing; } location @file-missing { rewrite ^(.*)$ /index.php?name=$1 last; } }