Error d"MIME (« text/html ») incorrect (X-Content-Type-Options: nosniff)" on deploy Django project with gunicorn and Apache

I'm trying to deploy a Django project with Gunicorn and Apache. The gunicorn is configured and working --> no problem on this side

The problem is with the statics files, i configure an apache conf :

<VirtualHost *:80>
    ProxyPass /static/ !
    ProxyPass / http://0.0.0.0:8002/
    ProxyPassReverse / http://0.0.0.0:8002/

    Alias /static/ /opt/livraison/apache/DEV

    <Directory /opt/livraison/apache/DEV>
        Require all granted
    </Directory>
    # Possible values for LogLevel : debug, info, notice, warn, error, crit, alert, emerg.
    LogLevel info
    ErrorLog /logs/PASPE_DEV/apache_error.log
    CustomLog "/logs/PASPE_DEV/access_log/apache.log" "%h %l %u %t \"%r\" %>s %b"
</VirtualHost>

And it seem that my static files are redirect to gunicorn so on port 8002 and not 80. and i got this error : adresse « http://server:8002/static/SuiviInstall/css/home.css » a été bloquée en raison d’un type MIME (« text/html ») incorrect (X-Content-Type-Options: nosniff)

How can i handle this error ?

Your ProxyPass /static/ ! must come before the ProxyPass / rule so Apache serves static files itself instead of forwarding them to Gunicorn. Also, make sure your Alias /static/ points to the correct static files directory and that Apache has permission to read them. The MIME error happens because Gunicorn returns an HTML 404 page instead of the CSS file when static requests get proxied to it.

Yes, absolutely. That error message:

"because search permissions are missing on a component of the path"

means that Apache (or the web server user) does not have execute (search) permission on one or more directories in the path to the static files.

Вернуться на верх