我试图在我的网络服务器(https://mywebsite.com/portfolio/downloads/MyFile.zip)上浏览并下载.zip文件,但是它会返回/var/www/html/index.php的HTML内容?它没有下载文件。
/ etc / nginx / sites-available / default contents:
server
{
# GENERAL CONFIGS
server_name MYWEBSITE.com;
location ^~ /.well-known {
allow all;
alias /var/www/html/.well-known/;
}
return 302 https://$server_name$request_uri;
}
server {
# SSL configuration
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/MYWEBSITE.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/MYWEBSITE.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
server_name MYWEBSITE.com;
root /var/www/html;
index index.php index.html index.htm;
location /projectdev/minigames/design.html {
deny all;
}
# ROOT Location
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /blog {
try_files $uri $uri/ /blog/index.php;
}
location /forum {
try_files $uri $uri/ /forum/public/index.php;
}
#location @rewrites {
# if (!-e $request_filename)
#{
# rewrite ^/(.*)$ /index.php/$1 last;
# break;
#}
#}
location = /favicon.ico {
access_log off;
log_not_found off;
}
# location ~ /\. {
# access_log off;
# log_not_found off;
# deny all;
# }
location ^~ /.well-known {
allow all;
alias /var/www/html/.well-known/;
}
# PHP Configs
fastcgi_intercept_errors on;
location ~ \.php {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
#fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param HTTPS on;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_index index.php;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
我的nginx配置中有什么错误,当你浏览它们时我的网络服务器不能下载.zip文件?
答案 0 :(得分:0)
这是导致重定向的行:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
它正在尝试提供文件,失败然后重定向到“/index.php?”
我在我的服务器上使用以下内容并且工作正常:
location / {
## try_files $uri @rewrite;
try_files $uri $uri/ =404;
autoindex on;
}
不要忘记在进行更改后重新加载nginx