Admin Panel failing at deployment

Hi Ken, I’ve done all the work according to the documentation more or less and I’ve run into this as well. It’s very frustrating for me as the admin panel was meant to be an integral part of the project.

I’m running django with gunicorn, I’m running an nginx web server, and I’m running a postgres db server. Collectstatic has been done. Files are moved. Everything is accessible.


According to inspect, the mimetype is not set correctly.

The stylesheet http://static.addohm.net/files/admin/css/nav_sidebar.css was not loaded because its MIME type, “text/plain”, is not “text/css”.

I’ve thus far tried the following:

If this post relates to me, thats even more frusterating because I can’t do a damn thing about it! It’s not MY favicon!

Here is a clip from my settings.py:

STATICFILES_DIRS = [
    BASE_DIR / "staticfiles",
]
STATIC_URL='https://static.addohm.net/files/'
STATIC_ROOT='/var/www/files'

Here is a screenshot of the STATIC_ROOT admin CSS location after having run collectstatic:

P.S. I’ve tried four different brands of browsers.

I came from this post here which has a wealth of information but nothing that worked for me.
Help: Django 4.2 admin page CSS issue - Using Django / The Admin - Django Forum

We need to see your nginx configuration for your project and your static files.

It may also help to see the nginx logs (access and error) for requests to those files.

I’ve since changed the folder locations, so please don’t mind the address change. As for the logs, there are no errors.

server conf

http{

  # Define custom log format to include reponse times
  log_format main_timed '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for" '
                          '$request_time $upstream_response_time $pipe $upstream_cache_status';

  access_log /var/log/nginx/nginx_http_access.log main_timed;
  error_log /var/log/nginx/nginx_http_error.log notice;

  # Hide headers that identify the server to prevent information leakage
  proxy_hide_header X-Powered-By;
  fastcgi_hide_header X-Powered-By;
  server_tokens off;

  # Enable gzip compression by default
  gzip on;
  gzip_proxied any;
  # Based on CloudFlare's recommended settings
  gzip_types text/richtext text/plain text/css text/x-script text/x-component text/x-java-source text/x>  gzip_vary on;
  gzip_disable "msie6";

  # Include server configs
  include /etc/nginx/http.d/*.conf;

}

events{}

http conf

server {
    listen 9999;
    client_max_body_size 64M;

    # Access meme
    location / {
      root /var/www/html;
      add_header Access-Control-Allow-Origin *;
      try_files $uri $uri/ /index.html;
      index  index.html index.htm;
    }

    location /static {
      alias /var/www/files/static;
      error_log /var/log/nginx/cdc-django_static_server_error.log notice;

      # Turn off in production
      autoindex on;
      autoindex_exact_size off;
      autoindex_localtime on;
    }

    location /media {
      alias /var/www/files/media;
      error_log /var/log/nginx/cdc-django_media_server_error.log notice;

      # Turn off in production
      autoindex on;
      autoindex_exact_size off;
      autoindex_localtime on;
    }
}

Please post the requested log contents for the requests for those files. (You are getting 404s on them, right?)

As I stated, the logs are empty. There are no errors. I’ll try to provoke this issue again.

Theres really no logs yet.

Here is firefox inspect as of this post.

Edge and Chrome show something different.

Logs

gunicorn output

Ok, these are not the nginx configuration information being applied here.

You’ve got some other definitions involved.

What is listening on port 443 on your server?

Please do not post images of textual information, they’re extremely difficult for me to read.

Copy/paste the text into the body of your post as you would any other code or template file (marked as preformatted text).

Sorry, its easier to show full context - like file structures.

It looks like nothing is listening in on :443

cdcalpinevm:/etc/nginx/http.d# netstat -l | grep :443
cdcalpinevm:/etc/nginx/http.d# 

As for the nginx configuration, I’m not sure how what you said is possible. I’ve posted all of the configuration files, above, in code blocks :slight_smile:

If nothing is listening to 443, then your requests for files on https are never going to work - and it has nothing to do with your Django / gunicorn configuration. (Look at the browser console log images you posted - the requests for those files are to “https” - which implies something thinks something is listening on 443.)

Also, your server directive above is configured to listen on port 9999

and I don’t see that referenced anywhere in these requests.

Also, you’ve got gunicorn configured to listen on port 8000 (which I can’t quote because you posted it as an image), and I don’t see anything in this configuration that will forward a request to 8000, so I don’t know how the requests are getting through nginx to gunicorn.

So no, this is not the complete information - there’s a lot going on that you haven’t posted or provided information for.

(That you are not getting any information in those nginx log files is just further confirmation that this isn’t the correct information being shown.)

I realized that last night but the same results are produced locally, or remote - securely, or not.

This server is a VM on an unraid rack. It’s sitting behind an NPM reverse proxy. Requests from domain files.addohm.net:80 http requests get forwarded as port 9999. Requests from domain dcdc.addohm.net:80 http requests get forwarded as port 8000 as well.

Maybe I should run it back a bit and remove all https request possibilities for now, but that still wouldn’t fix the problem as you can see in my reluctantly posted screenshot above, and earlier images shows that the images outside of the admin panel are accessible by django, http or https.

I don’t think its “incorrect” information so much as a lack of information. I’m doing my best to give you what you ask for. I don’t yet know why the logs aren’t filling with entries.

I run an almost identical setup, sans django at cdc.addohm.net albeit a much older version as that was a mockup prototype.

Im just going to put this down for the weekend. I’m as frustrated as you seem to be, if not more. At least I can marvel at my creation locally haha

Well, after plugging away at it most of the weekend, I got it. I’m not exactly sure which change fixed it yet but I will follow up when I find it.