0

I have a Nginx that runs behind docker.

Here's my .conf file

events {
  worker_connections  2048;
}

http {
    default_type application/octet-stream;

    server {
        listen 80;
        index index.php index.html;
        root /var/www/public;

        location / {
            try_files $uri /index.php?$args;
        }

        location ~ \.css {
            include  /etc/nginx/mime.types;
            add_header Content-Type text/css;
        }

        location ~ \.js {
            add_header Content-Type application/x-javascript;
        }

        location ~ ^/(assets/|css/|js/|index.html) {
            root /var/www/public;
            index index.html;
            access_log off;
        }

        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass app:9000;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
        }
    }
}

I've followed the solution here: Nginx fails to load css files

I also have tried the following:

  1. Put include /etc/nginx/mime.types; under http {

I've checked mime.types that it has the correct value as follows:

text/css                                         css;

The result that i am getting from Chrome dev console is this:

Accept-Ranges: bytes
Content-Length: 52806
Content-Type: text/plain
Content-Type: text/css
Date: Thu, 20 Sep 2018 09:49:35 GMT
ETag: "5ba0bfef-ce46"

For some reason, Nginx loads it as text/plain and text/css altogether.

This is the Nginx version that I am using:

Server: nginx/1.15.3

EDIT

Interestingly enough, if i do curl -v like this, it is being treated as text/css

Curl Result

Can anyone point me in the right direction? Thanks

Jeremy
  • 2,516
  • 8
  • 46
  • 80
  • 1
    `nginx` adds the mandatory Content-Type header automatically. Using `add_header` to create a second header is likely to confuse some browsers. The conventional approach for filenames with an extension, is to include mime.types at the top of the `server` block or the top of the `http` block. – Richard Smith Sep 20 '18 at 14:09
  • Does this mean i should remove everything within the /location block (css /location block) ? – Jeremy Sep 20 '18 at 14:31
  • The `location ~ \.css` block and `location ~ \.js` block should be completely deleted, and the `include /etc/nginx/mime.types;` placed elsewhere. – Richard Smith Sep 20 '18 at 14:36
  • Hi @RichardSmith thanks for the response, i tried that as well but i am still getting same result. For some reason, the "Content-Type:" is thrown twice (with different type, being css for one and text/plain for the other). – Jeremy Sep 21 '18 at 02:04

0 Answers0