The urls.py file:
from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
The settings.py file:
STATIC_URL = '/web/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_ROOT = '/home/domain.com/public_html/web/public/static'
I am using cyberpanel with openlightspeed server with contex:
context / {
type appserver
location /home/domain.com/public_html/web
binPath /usr/local/lsws/fcgi-bin/lswsgi
appType wsgi
startupFile web/wsgi.py
envType 1
env LS_PYTHONBIN=/home/domain.com/public_html/bin/pyhton
env PYTHONHOME=/home/domain.com/public_html/
}
My web app is not serving static files I am getting:
404 Not Found
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!
Hi there,
Here’s a general approach you could try to diagnose and fix the issue:
Check the Paths: Make sure that the paths in your settings.py are correct and accessible by the web server.
Configure OpenLiteSpeed to Serve Static Files: You’ll need to add a context for serving static files in your OpenLiteSpeed configuration. This will tell OpenLiteSpeed where to find the static files and serve them directly without going through your Django app.
You can add the following context to your OpenLiteSpeed configuration file or through the admin interface:
context /web/static/ {
type static
location /home/domain.com/public_html/web/public/static
allowBrowse 1
rewrite {
enable 0
}
addDefaultCharset off
expireInSeconds 604800
}
Make sure to adjust the paths as needed based on your directory structure.
Collect Static Files: Run the collectstatic command to make sure all your static files are in the correct location:
python manage.py collectstatic
Check Permissions: Ensure that the permissions are set correctly on the static files directory so that OpenLiteSpeed can read them.
Restart OpenLiteSpeed: Finally, you’ll need to restart OpenLiteSpeed to apply the changes:
sudo /usr/local/lsws/bin/lswsctrl restart
Verify URLs: Verify that the URLs to your static files in your HTML templates are being rendered with the correct path based on your STATIC_URL setting.
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.