Question

Nginx content header response for static asset files(css,js,image etc) is type/html

below is configuration for virtual hosts

server {
	listen 80 default_server;
	#listen [::]:80 default_server ipv6only=on;


	root /var/www/html;
	index index.php index.html index.htm;

	# Make site accessible from http://localhost/
	server_name domainname.com www.domainname.com;

 location / {
                index index.php;
                include /etc/nginx/mime.types;
                location ~.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ {
                expires 7d;
                }

                location ~* \.php$ {
                fastcgi_index   index.php;

                 fastcgi_pass    127.0.0.1:9000;
#                fastcgi_pass unix:/var/run/php5-fpm.sock;
                include         fastcgi_params;
                fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
                fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
                }
          }

          if (!-e $request_filename)
          {
                rewrite ^(.+)$ /index.php?q=$1 last;
          }

          location ~ /\.ht {
          deny all;
          }
       }

But all images,stylesheets,js files are rendered with headerresponse as type/html. This happened when the droplet was power off on after we faced connection timeout error. Any help is appreciated.

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

I had similar problem and I was able to fix it by setting up a new location directive for my image path

Hi @shanbhagvikrant,

There is an module for Nginx called HttpHeadersMoreModule that gives you more control over headers. It does not come with Nginx and requires additional installation. With it, you can do something like this:

location ... {
  more_set_headers "Server: my_server";
}

That will “set the Server output header to the custom value for any status code and any content type”. It will replace headers that are already set or add them if unset.

Additionally, depending on your Nginx Version, you should be able to configure something like this as well

server {
    server_name  .myserver.com
    location / {
        proxy_pass  http://mybackend;
        add_header  $header;
    }
}

Regards, KDSys

This comment has been deleted