Deploy Static files

Hi, I am new to django and my original lenguage isn’t english.

I am using django 4.2.10 in debian 11 with apache 2.4 and mod-wsgi.

As my development process before django had been I have my entire application under apache root in a subdirectory example.com/seguridad (except SECRET_KEY).

This is my django.conf in apache

Alias static/ /home/tierra/Arbol_de_Vida/2_Para_Conocerme_como_Soy/Creatividad_en/.django/static/

<Directory /home/tierra/Arbol_de_Vida/2_Para_Conocerme_como_Soy/Creatividad_en/.django/static>
    Require all granted
</Directory>

WSGIDaemonProcess example.com python-home=/home/tierra/Arbol_de_Vida/2_Para_Conocerme_como_Soy/Creatividad_en/seguridad/virtual python-path=/home/tierra/Arbol_de_Vida/2_Para_Conocerme_como_Soy/Creatividad_en/seguridad/data
WSGIProcessGroup example.com
WSGIScriptAlias /seguridad /home/tierra/Arbol_de_Vida/2_Para_Conocerme_como_Soy/Creatividad_en/seguridad/data/data/wsgi.py process-group=example.com

Besides the django application static files everything else work fine in example.com and example.com/seguridad

This is in my settings.py

DEBUG = False

STATIC_URL = 'static/'

STATIC_ROOT = "/home/tierra/Arbol_de_Vida/2_Para_Conocerme_como_Soy/Creatividad_en/.django/static/"

I copied static files with python manage.py collectstatic to STATIC_ROOT and it has read permissions to apache, but browser console say: 404 not found in http://192.168.1.73/seguridad/static/images/prioridades.jpg (I even change STATIC_ROOT to /home/tierra/Arbol_de_Vida/2_Para_Conocerme_como_Soy/Creatividad_en/seguridad/static/ just to make sure but with same result).

I think I used everything in docs about managing and deploying static files and searched the web but seems that every case is very particular. What I am missing? Thanks in advance.

1 Like

Thinking that the problem may be having the django app inside the apache root directory I took it out redoing all steps, to the same situation with static files.

So far besides that I have other two odd problems with django:

  • Can’t write to database from form, database read only. If I change permissions of proyect folder and database file to www-data it works but the I can’t migrate models from normal user with python3 manage.py migrate.
  • I have a class-based view that can only be accessed with is_staff permission redirecting to login_url, which don’t respect the subdirectory the aplication is in. The url for login is created automatically at example.com/seguridad/accounts/login/ but the view redirects to example.com/accounts/login/. I can overcome this setting LOGIN_URL = 'seguridad/accounts/login' but I don’t know why this happens.

Anyway if I must choose the static files problem is the most important, thank you.

1 Like

Briefly reviewing the two key settings:

STATIC_ROOT = The location where static files are going to be copied using the collectstatic command.

The user running collectstatic must have “write” permissions to that directory, including the ability to create subdirectories.

The web server must have “read” permissions to this entire directory tree.

In the common case, this directory should be outside your project directory. It’s actually quite common to define this within /var/www/ or even /var/www/html/ on Unix-style systems.

STATIC_URL = The base URL for creating references to static files. This setting has no meaning with Django, other than for creating URLs being referenced within the static tag used in templates.

This is the URL path that you will associate with STATIC_ROOT in your web server configuration.

For example, if you have:
STATIC_ROOT = '/var/www/html/project1'
and
STATIC_URL='/static/'

Then your web server needs to be configured such that the location /static causes the web server to retrieve files from /var/www/html/project1

The most common issues I see with handling static files include:

  • Using a STATIC_ROOT inside the project directory
  • Not assigning proper permissions to the STATIC_ROOT directory.
  • Not having the web server configured to map STATIC_URL to STATIC_ROOT
  • Not running collectstatic
1 Like

Hi thanks for answering.
I had set STATIC_ROOT in setting.py to a folder inside the apache example.com root directory where all my other website files that are working well are, with the same read permission.
I ran collectstatic and the files where copied there succesfully.

How can I map STATIC_URL to STATIC_ROOT in the server? I tought it was adding Alias /static/ /path/to/STATIC_ROOT with its correspondent directory Require all granted in my django.conf where WSGIScriptAlias is but it didn’t work for me.

Look at your Apache error log. Find the requests for the static files.

Yes, your alias directive looks correct. (However, I still maintain that it’s not the best idea to have it referencing a directory in your /home directory.)

Note: The Apache web server does not read your project files, nor does it have any need to. It’s the mod_wsgi process that runs the Python interpreter, and it’s that process that reads your code. You really don’t want Apache to have access to your project.

1 Like

When I set up the server I didn’t want to keep updating the files in the website directory as they change very frecuently, so I pointed the server directory to where the files actually are. Now I know I can make a script to automate updating. There is a reason it should be in /var/www?

The apache error.log say: Not Found: /seguridad/static/images/prioridades.jpg so it is searching in a different path that the one set Alias /static/ in the django.conf. Even if I put the files in that path (/seguridad/static/… in website root directory) it gives same result.

My main website (one that don’t use django) is in the website root folder aka example.com so I set up django to work in a subdirectory as specified in the docs (example.com/seguridad) so maybe it has something to do with that?

As a note I have seen that the first trailing slash matter: seguridad/ and /seguridad/ (for some reason I solved the problem with the login_url setting it to /seguridad/accounts/login instead of seguridad/accounts/login) so I tried WSGIScriptAlias /seguridad /... and WSGIScriptAlias /seguridad/ /... but django app stopped working. The docs example use Alias /static/ instead of Alias static/ but I tried both to no avail. I think it has something to do about the [server - mod wsgi - django] configuration but I don’t know what. Thanks for your time.

One last thing I can think of is that I installed libapache2-mod-wsgi-py3 from debian repositories version 4.7.1.

Actually, no - static file issues have nothing to do with your wsgi process. That’s the purpose of doing all this.

You want apache to handle the static files itself. Django should have no part in handling static files in your production environment.

This leads me to believe that either:

  • You have another alias in your configs that is overriding this
  • You have a symlink somewhere in the path you’re describing

That’s the purpose of it. Doing this should not be a concern.

It’s the common, standard, and conventional place for static files. By default, the apache process is given all the necessary permissions to it.

1 Like

I set STATIC_ROOT = '/var/www/static', run collecstatic, confirm files existence and set www-data permissions to everything (where root), change Alias /static/ to that path with directory Require all granted. Reloaded apache. Same situation. I searched for another static Alias but found nothing, I am using Let’s Encrypt HTTPS so I don’t know if that has something to do.

I am reading https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/modwsgi/#serving-the-admin-files and there is an option to

Create a symbolic link to the admin static files from within your document root (this may require +FollowSymLinks in your Apache configuration).

Probably that would work. I am going to try when I really need those static files, right now I wanted css files to style templates so I worked around including style tags. Thank you.

If you’re looking for assistance with this, please remember to post the information that is going to help us help you diagnose this.

In this case, please post the actual entry section in your apache conf file, along with the full error messages from the apache error log.

It would also be helpful to see the output of an ls -l command for /var/www and /var/www/static

1 Like

This is etc/apache2/conf-available/django.conf

Alias /static/ /var/www/static/

<Directory /var/www/static>
    Require all granted
</Directory>

WSGIDaemonProcess example.com python-home=/home/tierra/Arbol_de_Vida/2_Para_Conocerme_como_Soy/un_Espacio_Seguro/Proyectos/Data/virtual python-path=/home/tierra/Arbol_de_Vida/2_Para_Conocerme_como_Soy/un_Espacio_Seguro/Proyectos/Data/data
WSGIProcessGroup example.com
WSGIScriptAlias /seguridad /home/tierra/Arbol_de_Vida/2_Para_Conocerme_como_Soy/un_Espacio_Seguro/Proyectos/Data/data/data/wsgi.py process-group=example.com

<Directory /home/tierra/Arbol_de_Vida/2_Para_Conocerme_como_Soy/un_Espacio_Seguro/Proyectos/Data/data/data>
<Files wsgi.py>
    Require all granted
</Files>
</Directory>

This is main site etc/apache2/sites-available/example.com.conf

<VirtualHost *:80>
	ServerName example.com
	ServerAlias www.example.com
	DocumentRoot /home/tierra/Arbol_de_Vida/2_Para_Conocerme_como_Soy/Creatividad_en
        <Directory /home/tierra/Arbol_de_Vida/2_Para_Conocerme_como_Soy/Creatividad_en>
            Options -Indexes +FollowSymLinks
	    Require all granted
        </Directory>

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

etc/apache2/sites-available/example.com-le-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
	ServerName example.com
	ServerAlias www.example.com
	DocumentRoot /home/tierra/Arbol_de_Vida/2_Para_Conocerme_como_Soy/Creatividad_en
        <Directory /home/tierra/Arbol_de_Vida/2_Para_Conocerme_como_Soy/Creatividad_en>
            Options -Indexes +FollowSymLinks
	    Require all granted
        </Directory>

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
</VirtualHost>
</IfModule>

apache2.conf only has default, log, security and include settings, do you need it?

apache error log of today repeating same message

[Mon Feb 26 00:01:28.265915 2024] [mpm_event:notice] [pid 618:tid 548092695616] AH00489: Apache/2.4.56 (Debian) OpenSSL/1.1.1w mod_wsgi/4.7.1 Python/3.9 configured -- resuming normal operations
[Mon Feb 26 00:01:28.266099 2024] [core:notice] [pid 618:tid 548092695616] AH00094: Command line: '/usr/sbin/apache2'
[Mon Feb 26 05:43:59.025925 2024] [wsgi:error] [pid 16683:tid 547949650304] [remote 192.168.1.72:59138] Not Found: /seguridad/static/admin/js/theme.js
[Mon Feb 26 05:43:59.032874 2024] [wsgi:error] [pid 16683:tid 547974828416] [remote 192.168.1.72:59154] Not Found: /seguridad/static/admin/js/nav_sidebar.js
[Mon Feb 26 05:43:59.047132 2024] [wsgi:error] [pid 16683:tid 547958043008] [remote 192.168.1.72:59152] Not Found: /seguridad/static/admin/css/nav_sidebar.css
[Mon Feb 26 05:43:59.058298 2024] [wsgi:error] [pid 16683:tid 547941257600] [remote 192.168.1.72:59126] Not Found: /seguridad/static/admin/css/base.css
[Mon Feb 26 05:43:59.061815 2024] [wsgi:error] [pid 16683:tid 547966435712] [remote 192.168.1.72:59164] Not Found: /seguridad/static/admin/css/login.css
[Mon Feb 26 05:43:59.065681 2024] [wsgi:error] [pid 16683:tid 548058755456] [remote 192.168.1.72:59128] Not Found: /seguridad/static/admin/css/dark_mode.css
[Mon Feb 26 05:43:59.077440 2024] [wsgi:error] [pid 16683:tid 547983221120] [remote 192.168.1.72:59138] Not Found: /seguridad/static/admin/css/responsive.css
[Mon Feb 26 05:44:01.469143 2024] [wsgi:error] [pid 16683:tid 547949650304] [remote 192.168.1.72:59152] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 05:44:01.487363 2024] [wsgi:error] [pid 16683:tid 547983221120] [remote 192.168.1.72:59138] Not Found: /seguridad/static/images/prioridades.jpg
[Mon Feb 26 05:44:02.725668 2024] [wsgi:error] [pid 16683:tid 547983221120] [remote 192.168.1.72:59152] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 05:44:02.743915 2024] [wsgi:error] [pid 16683:tid 547949650304] [remote 192.168.1.72:59138] Not Found: /seguridad/static/images/prioridades.jpg
[Mon Feb 26 05:44:33.587255 2024] [wsgi:error] [pid 16683:tid 547949650304] [remote 192.168.1.72:38744] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 05:44:33.621035 2024] [wsgi:error] [pid 16683:tid 547983221120] [remote 192.168.1.72:38744] Not Found: /seguridad/static/images/prioridades.jpg
[Mon Feb 26 05:44:56.292563 2024] [wsgi:error] [pid 16683:tid 547983221120] [remote 185.243.218.95:59954] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 05:44:57.702721 2024] [wsgi:error] [pid 16683:tid 547949650304] [remote 185.243.218.95:59954] Not Found: /seguridad/static/images/prioridades.jpg
[Mon Feb 26 05:45:07.091008 2024] [wsgi:error] [pid 16683:tid 547983221120] [remote 185.243.218.95:57300] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 05:45:07.494142 2024] [wsgi:error] [pid 16683:tid 547949650304] [remote 185.243.218.95:57300] Not Found: /seguridad/static/images/prioridades.jpg
[Mon Feb 26 05:51:39.113596 2024] [mpm_event:notice] [pid 618:tid 548092695616] AH00493: SIGUSR1 received.  Doing graceful restart
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
[Mon Feb 26 05:51:39.511115 2024] [mpm_event:notice] [pid 618:tid 548092695616] AH00489: Apache/2.4.56 (Debian) OpenSSL/1.1.1w mod_wsgi/4.7.1 Python/3.9 configured -- resuming normal operations
[Mon Feb 26 05:51:39.511214 2024] [core:notice] [pid 618:tid 548092695616] AH00094: Command line: '/usr/sbin/apache2'
[Mon Feb 26 05:53:17.836132 2024] [wsgi:error] [pid 18181:tid 547941257600] [remote 192.168.1.72:60028] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 05:53:17.855539 2024] [wsgi:error] [pid 18181:tid 548058755456] [remote 192.168.1.72:60028] Not Found: /seguridad/static/images/prioridades.jpg
[Mon Feb 26 05:54:23.889479 2024] [wsgi:error] [pid 18181:tid 548058755456] [remote 192.168.1.72:44712] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 05:54:23.925319 2024] [wsgi:error] [pid 18181:tid 547941257600] [remote 192.168.1.72:44712] Not Found: /seguridad/static/images/prioridades.jpg
[Mon Feb 26 05:54:56.940028 2024] [mpm_event:notice] [pid 618:tid 548092695616] AH00492: caught SIGWINCH, shutting down gracefully
[Mon Feb 26 05:55:08.533020 2024] [mpm_event:notice] [pid 622:tid 548587508800] AH00489: Apache/2.4.56 (Debian) OpenSSL/1.1.1w mod_wsgi/4.7.1 Python/3.9 configured -- resuming normal operations
[Mon Feb 26 05:55:08.577818 2024] [core:notice] [pid 622:tid 548587508800] AH00094: Command line: '/usr/sbin/apache2'
[Mon Feb 26 05:58:40.384362 2024] [wsgi:error] [pid 623:tid 548545175936] [remote 192.168.1.72:42432] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 05:58:45.182448 2024] [wsgi:error] [pid 623:tid 548519997824] [remote 192.168.1.72:42432] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 05:58:45.274694 2024] [wsgi:error] [pid 623:tid 548545175936] [remote 192.168.1.72:41414] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 05:58:53.127416 2024] [wsgi:error] [pid 623:tid 548545175936] [remote 192.168.1.72:51612] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 05:58:53.146471 2024] [wsgi:error] [pid 623:tid 548519997824] [remote 192.168.1.72:51612] Not Found: /seguridad/static/images/prioridades.jpg
[Mon Feb 26 06:00:16.726510 2024] [wsgi:error] [pid 623:tid 548519997824] [remote 192.168.1.72:45074] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 06:00:16.760745 2024] [wsgi:error] [pid 623:tid 548545175936] [remote 192.168.1.72:45074] Not Found: /seguridad/static/images/prioridades.jpg
[Mon Feb 26 06:00:18.371694 2024] [wsgi:error] [pid 623:tid 548545175936] [remote 192.168.1.72:45088] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 06:00:18.409981 2024] [wsgi:error] [pid 623:tid 548519997824] [remote 192.168.1.72:45088] Not Found: /seguridad/static/images/prioridades.jpg
[Mon Feb 26 06:00:49.210233 2024] [wsgi:error] [pid 623:tid 548436070784] [remote 193.218.118.91:39124] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 06:00:50.068284 2024] [wsgi:error] [pid 623:tid 548519997824] [remote 193.218.118.91:39124] Not Found: /seguridad/static/images/prioridades.jpg
[Mon Feb 26 06:49:20.934739 2024] [wsgi:error] [pid 623:tid 548545175936] [remote 192.168.1.72:50900] Not Found: /seguridad/static/admin/js/theme.js
[Mon Feb 26 06:49:20.945980 2024] [wsgi:error] [pid 623:tid 548452856192] [remote 192.168.1.72:50912] Not Found: /seguridad/static/admin/css/nav_sidebar.css
[Mon Feb 26 06:49:20.967462 2024] [wsgi:error] [pid 623:tid 548436070784] [remote 192.168.1.72:50872] Not Found: /seguridad/static/admin/css/base.css
[Mon Feb 26 06:49:20.977147 2024] [wsgi:error] [pid 623:tid 548461248896] [remote 192.168.1.72:50922] Not Found: /seguridad/static/admin/css/login.css
[Mon Feb 26 06:49:20.981758 2024] [wsgi:error] [pid 623:tid 548519997824] [remote 192.168.1.72:50884] Not Found: /seguridad/static/admin/css/dark_mode.css
[Mon Feb 26 06:49:20.993540 2024] [wsgi:error] [pid 623:tid 548444463488] [remote 192.168.1.72:50918] Not Found: /seguridad/static/admin/js/nav_sidebar.js
[Mon Feb 26 06:49:20.998316 2024] [wsgi:error] [pid 623:tid 548469641600] [remote 192.168.1.72:50900] Not Found: /seguridad/static/admin/css/responsive.css
[Mon Feb 26 06:49:24.459762 2024] [wsgi:error] [pid 623:tid 548469641600] [remote 192.168.1.72:50934] Not Found: /seguridad/static/admin/css/base.css
[Mon Feb 26 06:49:24.475576 2024] [wsgi:error] [pid 623:tid 548519997824] [remote 192.168.1.72:50952] Not Found: /seguridad/static/admin/css/nav_sidebar.css
[Mon Feb 26 06:49:24.481677 2024] [wsgi:error] [pid 623:tid 548444463488] [remote 192.168.1.72:50946] Not Found: /seguridad/static/admin/js/theme.js
[Mon Feb 26 06:49:24.507150 2024] [wsgi:error] [pid 623:tid 548545175936] [remote 192.168.1.72:50942] Not Found: /seguridad/static/admin/css/dark_mode.css
[Mon Feb 26 06:49:24.511903 2024] [wsgi:error] [pid 623:tid 548436070784] [remote 192.168.1.72:50978] Not Found: /seguridad/static/admin/css/login.css
[Mon Feb 26 06:49:24.516351 2024] [wsgi:error] [pid 623:tid 548461248896] [remote 192.168.1.72:50962] Not Found: /seguridad/static/admin/js/nav_sidebar.js
[Mon Feb 26 06:49:24.521012 2024] [wsgi:error] [pid 623:tid 548452856192] [remote 192.168.1.72:50934] Not Found: /seguridad/static/admin/css/responsive.css
[Mon Feb 26 06:56:08.993386 2024] [wsgi:error] [pid 623:tid 548452856192] [remote 192.168.1.72:54706] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 06:56:09.026895 2024] [wsgi:error] [pid 623:tid 548469641600] [remote 192.168.1.72:54706] Not Found: /seguridad/static/images/prioridades.jpg
[Mon Feb 26 06:56:38.021393 2024] [wsgi:error] [pid 623:tid 548452856192] [remote 192.168.1.72:52220] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 06:56:38.039602 2024] [wsgi:error] [pid 623:tid 548469641600] [remote 192.168.1.72:52220] Not Found: /seguridad/static/images/prioridades.jpg
[Mon Feb 26 06:56:44.682969 2024] [wsgi:error] [pid 623:tid 548469641600] [remote 192.168.1.72:52246] Not Found: /seguridad/static/admin/css/base.css
[Mon Feb 26 06:56:44.704080 2024] [wsgi:error] [pid 623:tid 548452856192] [remote 192.168.1.72:52266] Not Found: /seguridad/static/admin/js/theme.js
[Mon Feb 26 06:56:44.719216 2024] [wsgi:error] [pid 623:tid 548436070784] [remote 192.168.1.72:52270] Not Found: /seguridad/static/admin/css/responsive.css
[Mon Feb 26 06:56:44.724934 2024] [wsgi:error] [pid 623:tid 548461248896] [remote 192.168.1.72:52252] Not Found: /seguridad/static/admin/css/dark_mode.css
[Mon Feb 26 06:58:21.152968 2024] [wsgi:error] [pid 623:tid 548545175936] [remote 192.168.1.72:48414] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 06:58:21.186704 2024] [wsgi:error] [pid 623:tid 548461248896] [remote 192.168.1.72:48414] Not Found: /seguridad/static/images/prioridades.jpg
[Mon Feb 26 06:58:27.630552 2024] [wsgi:error] [pid 623:tid 548545175936] [remote 192.168.1.72:45244] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 06:58:27.648819 2024] [wsgi:error] [pid 623:tid 548461248896] [remote 192.168.1.72:45244] Not Found: /seguridad/static/images/prioridades.jpg
[Mon Feb 26 07:04:36.977821 2024] [wsgi:error] [pid 623:tid 548461248896] [remote 192.168.1.72:41614] Not Found: /seguridad/static/admin/css/nav_sidebar.css
[Mon Feb 26 07:04:36.991504 2024] [wsgi:error] [pid 623:tid 548444463488] [remote 192.168.1.72:41622] Not Found: /seguridad/static/admin/css/dashboard.css
[Mon Feb 26 07:04:36.996235 2024] [wsgi:error] [pid 623:tid 548545175936] [remote 192.168.1.72:41596] Not Found: /seguridad/static/admin/css/dark_mode.css
[Mon Feb 26 07:04:37.002250 2024] [wsgi:error] [pid 623:tid 548452856192] [remote 192.168.1.72:41586] Not Found: /seguridad/static/admin/css/base.css
[Mon Feb 26 07:04:37.007164 2024] [wsgi:error] [pid 623:tid 548436070784] [remote 192.168.1.72:41600] Not Found: /seguridad/static/admin/js/theme.js
[Mon Feb 26 07:04:37.015788 2024] [wsgi:error] [pid 623:tid 548469641600] [remote 192.168.1.72:41618] Not Found: /seguridad/static/admin/js/nav_sidebar.js
[Mon Feb 26 07:04:37.028639 2024] [wsgi:error] [pid 623:tid 548519997824] [remote 192.168.1.72:41614] Not Found: /seguridad/static/admin/css/responsive.css
[Mon Feb 26 07:12:48.261298 2024] [wsgi:error] [pid 3057:tid 548545175936] [remote 192.168.1.72:47564] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 07:12:48.280015 2024] [wsgi:error] [pid 3057:tid 548553568640] [remote 192.168.1.72:47564] Not Found: /seguridad/static/images/prioridades.jpg
[Mon Feb 26 07:12:50.713005 2024] [wsgi:error] [pid 3057:tid 548553568640] [remote 192.168.1.72:47564] Not Found: /seguridad/static/css/formas.css
[Mon Feb 26 07:12:50.731403 2024] [wsgi:error] [pid 3057:tid 548545175936] [remote 192.168.1.72:47570] Not Found: /seguridad/static/images/prioridades.jpg
[Mon Feb 26 07:53:46.238843 2024] [wsgi:error] [pid 3934:tid 548371669376] [remote 192.168.1.72:38576] Not Found: /seguridad/static/admin/js/nav_sidebar.js
[Mon Feb 26 07:53:46.245714 2024] [wsgi:error] [pid 3934:tid 548388454784] [remote 192.168.1.72:38580] Not Found: /seguridad/static/admin/css/dashboard.css
[Mon Feb 26 07:53:46.265254 2024] [wsgi:error] [pid 3934:tid 548380062080] [remote 192.168.1.72:38574] Not Found: /seguridad/static/admin/css/nav_sidebar.css
[Mon Feb 26 07:53:46.269389 2024] [wsgi:error] [pid 3934:tid 548545175936] [remote 192.168.1.72:38566] Not Found: /seguridad/static/admin/js/theme.js
[Mon Feb 26 07:53:46.273097 2024] [wsgi:error] [pid 3934:tid 548553568640] [remote 192.168.1.72:38550] Not Found: /seguridad/static/admin/css/base.css
[Mon Feb 26 07:53:46.276630 2024] [wsgi:error] [pid 3934:tid 548363276672] [remote 192.168.1.72:38564] Not Found: /seguridad/static/admin/css/dark_mode.css
[Mon Feb 26 07:53:46.288483 2024] [wsgi:error] [pid 3934:tid 548396847488] [remote 192.168.1.72:38576] Not Found: /seguridad/static/admin/css/responsive.css
[Mon Feb 26 07:55:26.227347 2024] [wsgi:error] [pid 3969:tid 548371669376] [remote 192.168.1.72:54036] Not Found: /seguridad/static/admin/js/nav_sidebar.js
[Mon Feb 26 07:55:26.232366 2024] [wsgi:error] [pid 3969:tid 548363276672] [remote 192.168.1.72:54024] Not Found: /seguridad/static/admin/css/nav_sidebar.css
[Mon Feb 26 07:55:26.236563 2024] [wsgi:error] [pid 3969:tid 548380062080] [remote 192.168.1.72:54014] Not Found: /seguridad/static/admin/js/theme.js
[Mon Feb 26 07:55:26.247526 2024] [wsgi:error] [pid 3969:tid 548545175936] [remote 192.168.1.72:38800] Not Found: /seguridad/static/admin/css/base.css
[Mon Feb 26 07:55:26.260297 2024] [wsgi:error] [pid 3969:tid 548388454784] [remote 192.168.1.72:54044] Not Found: /seguridad/static/admin/css/dashboard.css
[Mon Feb 26 07:55:26.265290 2024] [wsgi:error] [pid 3969:tid 548396847488] [remote 192.168.1.72:54036] Not Found: /seguridad/static/admin/css/responsive.css
[Mon Feb 26 07:55:26.268345 2024] [wsgi:error] [pid 3969:tid 548553568640] [remote 192.168.1.72:54012] Not Found: /seguridad/static/admin/css/dark_mode.css
[Mon Feb 26 07:55:33.024502 2024] [wsgi:error] [pid 3969:tid 548396847488] [remote 192.168.1.72:54070] Not Found: /seguridad/static/admin/js/theme.js
[Mon Feb 26 07:55:33.033161 2024] [wsgi:error] [pid 3969:tid 548553568640] [remote 192.168.1.72:54052] Not Found: /seguridad/static/admin/css/base.css
[Mon Feb 26 07:55:33.040421 2024] [wsgi:error] [pid 3969:tid 548545175936] [remote 192.168.1.72:54102] Not Found: /seguridad/static/admin/css/changelists.css
[Mon Feb 26 07:55:33.045951 2024] [wsgi:error] [pid 3969:tid 548380062080] [remote 192.168.1.72:54092] Not Found: /seguridad/static/admin/js/nav_sidebar.js
[Mon Feb 26 07:55:33.052317 2024] [wsgi:error] [pid 3969:tid 548371669376] [remote 192.168.1.72:54078] Not Found: /seguridad/static/admin/css/nav_sidebar.css
[Mon Feb 26 07:55:33.104390 2024] [wsgi:error] [pid 3969:tid 548388454784] [remote 192.168.1.72:54060] Not Found: /seguridad/static/admin/css/dark_mode.css
[Mon Feb 26 07:55:33.117569 2024] [wsgi:error] [pid 3969:tid 548396847488] [remote 192.168.1.72:54092] Not Found: /seguridad/static/admin/js/admin/RelatedObjectLookups.js
[Mon Feb 26 07:55:33.145740 2024] [wsgi:error] [pid 3969:tid 548405240192] [remote 192.168.1.72:54102] Not Found: /seguridad/static/admin/js/core.js
[Mon Feb 26 07:55:33.158111 2024] [wsgi:error] [pid 3969:tid 548363276672] [remote 192.168.1.72:54052] Not Found: /seguridad/static/admin/js/jquery.init.js
[Mon Feb 26 07:55:33.170668 2024] [wsgi:error] [pid 3969:tid 548380062080] [remote 192.168.1.72:54078] Not Found: /seguridad/static/admin/js/actions.js
[Mon Feb 26 07:55:33.172453 2024] [wsgi:error] [pid 3969:tid 548553568640] [remote 192.168.1.72:54070] Not Found: /seguridad/static/admin/js/vendor/jquery/jquery.js
[Mon Feb 26 07:55:33.202419 2024] [wsgi:error] [pid 3969:tid 548371669376] [remote 192.168.1.72:54102] Not Found: /seguridad/static/admin/js/vendor/xregexp/xregexp.js
[Mon Feb 26 07:55:33.219849 2024] [wsgi:error] [pid 3969:tid 548388454784] [remote 192.168.1.72:54092] Not Found: /seguridad/static/admin/js/prepopulate.js
[Mon Feb 26 07:55:33.223389 2024] [wsgi:error] [pid 3969:tid 548545175936] [remote 192.168.1.72:54060] Not Found: /seguridad/static/admin/js/urlify.js
[Mon Feb 26 07:55:33.228481 2024] [wsgi:error] [pid 3969:tid 548405240192] [remote 192.168.1.72:54052] Not Found: /seguridad/static/admin/js/filters.js
[Mon Feb 26 07:55:33.240920 2024] [wsgi:error] [pid 3969:tid 548380062080] [remote 192.168.1.72:54078] Not Found: /seguridad/static/admin/css/responsive.css
[Mon Feb 26 07:55:33.277780 2024] [wsgi:error] [pid 3969:tid 548553568640] [remote 192.168.1.72:54092] Not Found: /seguridad/static/admin/js/vendor/jquery/jquery.js
[Mon Feb 26 07:55:33.302433 2024] [wsgi:error] [pid 3969:tid 548363276672] [remote 192.168.1.72:54092] Not Found: /seguridad/static/admin/js/jquery.init.js
[Mon Feb 26 07:55:33.326548 2024] [wsgi:error] [pid 3969:tid 548553568640] [remote 192.168.1.72:54092] Not Found: /seguridad/static/admin/js/core.js
[Mon Feb 26 07:55:33.350664 2024] [wsgi:error] [pid 3969:tid 548363276672] [remote 192.168.1.72:54092] Not Found: /seguridad/static/admin/js/admin/RelatedObjectLookups.js
[Mon Feb 26 07:55:33.374708 2024] [wsgi:error] [pid 3969:tid 548553568640] [remote 192.168.1.72:54092] Not Found: /seguridad/static/admin/js/actions.js
[Mon Feb 26 07:55:33.399361 2024] [wsgi:error] [pid 3969:tid 548363276672] [remote 192.168.1.72:54092] Not Found: /seguridad/static/admin/js/urlify.js
[Mon Feb 26 07:55:33.424609 2024] [wsgi:error] [pid 3969:tid 548553568640] [remote 192.168.1.72:54092] Not Found: /seguridad/static/admin/js/prepopulate.js
[Mon Feb 26 07:55:33.452954 2024] [wsgi:error] [pid 3969:tid 548363276672] [remote 192.168.1.72:54092] Not Found: /seguridad/static/admin/js/vendor/xregexp/xregexp.js
[Mon Feb 26 07:55:33.491578 2024] [wsgi:error] [pid 3969:tid 548363276672] [remote 192.168.1.72:54052] Not Found: /seguridad/static/admin/css/responsive.css
[Mon Feb 26 07:55:33.496218 2024] [wsgi:error] [pid 3969:tid 548553568640] [remote 192.168.1.72:54092] Not Found: /seguridad/static/admin/js/filters.js
[Mon Feb 26 14:03:34.995431 2024] [mpm_event:notice] [pid 622:tid 548587508800] AH00493: SIGUSR1 received.  Doing graceful restart
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
[Mon Feb 26 14:03:35.393873 2024] [mpm_event:notice] [pid 622:tid 548587508800] AH00489: Apache/2.4.56 (Debian) OpenSSL/1.1.1w mod_wsgi/4.7.1 Python/3.9 configured -- resuming normal operations
[Mon Feb 26 14:03:35.394008 2024] [core:notice] [pid 622:tid 548587508800] AH00094: Command line: '/usr/sbin/apache2'
[Mon Feb 26 14:03:50.268716 2024] [wsgi:error] [pid 5675:tid 548452856192] [remote 192.168.1.72:35880] Not Found: /seguridad/static/admin/css/dark_mode.css
[Mon Feb 26 14:03:50.306431 2024] [wsgi:error] [pid 5675:tid 548503212416] [remote 192.168.1.72:35894] Not Found: /seguridad/static/admin/js/theme.js
[Mon Feb 26 14:03:50.310128 2024] [wsgi:error] [pid 5675:tid 548436070784] [remote 192.168.1.72:35908] Not Found: /seguridad/static/admin/js/nav_sidebar.js
[Mon Feb 26 14:03:50.319678 2024] [wsgi:error] [pid 5675:tid 548486427008] [remote 192.168.1.72:35904] Not Found: /seguridad/static/admin/css/nav_sidebar.css
[Mon Feb 26 14:03:50.330074 2024] [wsgi:error] [pid 5675:tid 548553568640] [remote 192.168.1.72:35872] Not Found: /seguridad/static/admin/css/base.css
[Mon Feb 26 14:03:50.338946 2024] [wsgi:error] [pid 5675:tid 548444463488] [remote 192.168.1.72:35912] Not Found: /seguridad/static/admin/css/dashboard.css
[Mon Feb 26 14:03:50.339838 2024] [wsgi:error] [pid 5675:tid 548494819712] [remote 192.168.1.72:35880] Not Found: /seguridad/static/admin/css/responsive.css
[Mon Feb 26 14:03:52.113373 2024] [wsgi:error] [pid 5675:tid 548494819712] [remote 192.168.1.72:35904] Not Found: /seguridad/static/admin/css/base.css
[Mon Feb 26 14:03:52.178926 2024] [wsgi:error] [pid 5675:tid 548436070784] [remote 192.168.1.72:35894] Not Found: /seguridad/static/admin/css/dashboard.css
[Mon Feb 26 14:03:52.188018 2024] [wsgi:error] [pid 5675:tid 548444463488] [remote 192.168.1.72:35908] Not Found: /seguridad/static/admin/js/theme.js
[Mon Feb 26 14:03:52.200176 2024] [wsgi:error] [pid 5675:tid 548486427008] [remote 192.168.1.72:35912] Not Found: /seguridad/static/admin/css/nav_sidebar.css
[Mon Feb 26 14:03:52.206428 2024] [wsgi:error] [pid 5675:tid 548553568640] [remote 192.168.1.72:35872] Not Found: /seguridad/static/admin/js/nav_sidebar.js
[Mon Feb 26 14:03:52.218416 2024] [wsgi:error] [pid 5675:tid 548461248896] [remote 192.168.1.72:35880] Not Found: /seguridad/static/admin/css/dark_mode.css
[Mon Feb 26 14:03:52.223005 2024] [wsgi:error] [pid 5675:tid 548503212416] [remote 192.168.1.72:35904] Not Found: /seguridad/static/admin/css/responsive.css
[Mon Feb 26 14:07:52.832022 2024] [wsgi:error] [pid 5804:tid 548380062080] [remote 192.168.1.72:38136] Not Found: /seguridad/static/admin/css/nav_sidebar.css
[Mon Feb 26 14:07:52.858031 2024] [wsgi:error] [pid 5804:tid 548388454784] [remote 192.168.1.72:38146] Not Found: /seguridad/static/admin/css/dashboard.css
[Mon Feb 26 14:07:52.870956 2024] [wsgi:error] [pid 5804:tid 548363276672] [remote 192.168.1.72:38128] Not Found: /seguridad/static/admin/js/theme.js
[Mon Feb 26 14:07:52.887012 2024] [wsgi:error] [pid 5804:tid 548545175936] [remote 192.168.1.72:38124] Not Found: /seguridad/static/admin/css/base.css
[Mon Feb 26 14:07:52.890435 2024] [wsgi:error] [pid 5804:tid 548371669376] [remote 192.168.1.72:38144] Not Found: /seguridad/static/admin/js/nav_sidebar.js
[Mon Feb 26 14:07:52.894092 2024] [wsgi:error] [pid 5804:tid 548396847488] [remote 192.168.1.72:38136] Not Found: /seguridad/static/admin/css/responsive.css
[Mon Feb 26 14:07:52.894916 2024] [wsgi:error] [pid 5804:tid 548553568640] [remote 192.168.1.72:38126] Not Found: /seguridad/static/admin/css/dark_mode.css
[Mon Feb 26 14:10:32.761315 2024] [wsgi:error] [pid 5804:tid 548553568640] [remote 92.205.237.227:47480] Not Found: /seguridad/static/admin/css/base.css
[Mon Feb 26 14:10:33.266670 2024] [wsgi:error] [pid 5804:tid 548380062080] [remote 92.205.237.227:47480] Not Found: /seguridad/static/admin/css/dark_mode.css
[Mon Feb 26 14:10:33.848698 2024] [wsgi:error] [pid 5804:tid 548553568640] [remote 92.205.237.227:47514] Not Found: /seguridad/static/admin/css/login.css
[Mon Feb 26 14:10:33.961004 2024] [wsgi:error] [pid 5804:tid 548553568640] [remote 92.205.237.227:47492] Not Found: /seguridad/static/admin/js/nav_sidebar.js
[Mon Feb 26 14:10:33.964756 2024] [wsgi:error] [pid 5804:tid 548380062080] [remote 92.205.237.227:47528] Not Found: /seguridad/static/admin/css/responsive.css
[Mon Feb 26 14:10:34.026630 2024] [wsgi:error] [pid 5804:tid 548396847488] [remote 92.205.237.227:47502] Not Found: /seguridad/static/admin/js/theme.js
[Mon Feb 26 14:10:34.102734 2024] [wsgi:error] [pid 5804:tid 548380062080] [remote 92.205.237.227:47538] Not Found: /seguridad/static/admin/css/nav_sidebar.css

output of ls -l command for /var/www

total 8
drwxr-xr-x 2 root     root     4096 Jan  5  2023 html
drwxr-xr-x 5 www-data www-data 4096 Feb 26 13:55 static

and /var/www/static

total 16
drwxr-xr-x 5 www-data www-data 4096 Feb 26 13:55 admin
drwxr-xr-x 2 www-data www-data 4096 Feb 26 13:55 css
drwxr-xr-x 2 www-data www-data 4096 Feb 26 13:55 images

I see that debian made their own changes, in case it’s useful etc/apache2/apache2.conf

DefaultRuntimeDir ${APACHE_RUN_DIR}
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
Include ports.conf

<Directory />
	Options FollowSymLinks
	AllowOverride None
	Require all denied
</Directory>

<Directory /usr/share>
	AllowOverride None
	Require all granted
</Directory>

<Directory /var/www/>
	Options Indexes FollowSymLinks
	AllowOverride None
	Require all granted
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
	Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf

If you look at the rendered page in the browser, are you seeing references to

in the HTML? If so, then this is apparently being caused by:

being passed through to Django, and causing this to be prepended to the static tags being rendered. (See the note in STATIC_URL)

So what you want to do is change your alias to be:
Alias /seguridad/static/ /var/www/static/

1 Like

Wow that fixed it. Thank you! I would try to check docs to values I am using.

I think it would prevent others same difficulty to add a note here about

If you want to serve your project in a subdirectory (https://example.com/mysite in this example), you can add WSGIScriptAlias

that come in previous section.
Thanks again.

Deployment is one of those topics that is really tough to cover in the docs, because of the number of options and combinations available.

For example, for web servers you have options including Apache, nginx, Lightspeed, and Caddy. For WSGI containers, you have (at least) gunicorn, CherryPy and uWSGI. For ASGI containers, you have uvicorn and Daphne.

Every one of these can have different ways of configuring them to provide for multi-project isolation. And since all of these are external to Django, it could be labor-intensive to keep them all up-to-date. (It’s not so much that they change all-that-often, but someone would need to verify that the information remains valid.)

<opinion>
For example, our standard stack is nginx, uWSGI (with some instances of gunicorn), and Daphne for websockets. (I haven’t deployed to Apache in more than 10 years now. I’d be quite happy if the Apache docs were replaced with references to nginx - but with the recent acquisition of nginx by F5, I’m not sure that’s the best option either.)

So where I guess I’m landing on this is that the docs only provide a starting point, and if you want to change what is identified as the most basic solution, you’ll need to understand what you’re doing in that environment. Anything else really goes beyond being a “Django” topic.
</opinion>

1 Like