5

On my website, i have some validation file that i need to put in the document root that has no extension just "validation-file",

But when i try to open it from the browser, it downloads instead of opening, all other files with extensions like (.txt) can be opened normally,

My nginx (1.12) config:

server {
listen 80;
listen 443 ssl;

root /var/www/website;
error_log /var/log/nginx/website-error.log;
access_log /var/log/nginx/website-access.log;

index index.php index.html index.htm index.nginx-debian.html;

server_name website.com;
ssl_certificate /etc/ssl/website/nginx_bundle.crt;
ssl_certificate_key /etc/ssl/website/website.key;

location / {
    index index.php index.html;
    try_files $uri $uri/ =404 /index.php?q=$uri&$args;
}

# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
    root /var/www/website;

    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /var/www/website/$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_script_name;

}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
    deny all;
}
6

nginx determines the content type from the extension. If the file has no extension, it will use the default_type.

You can explicitly set the content type of this file by handling it within its own location block:

location = /validation-file {
    types {}
    default_type text/html;
}

Set default_type to whatever the file contains, e.g. text/html or text/plain, etc.

See this document for more.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.