CSS未与Nginx和Uwsgi出现在Django中
这是我的第一个真正的Django项目,我正在尝试使用Nginx和Uwsgi配置它以进行生产。它在数字海洋Ubuntu服务器上运行。除了服务静态CSS文件外,还设置了所有内容。这奇怪的是它提供静态图像和JavaScript文件,唯一不提供的是CSS。
这是我的nginx的网站配置文件('nebula'是ubuntu用户和django project的名称):
# configuration of the server
server {
server_name example.com www.example.com;
charset utf-8;
# max upload size
client_max_body_size 75M;
# Django media and static files
location /media {
alias /home/nebula/nebula/media;
}
location /assets {
alias /home/nebula/nebula/assets;
}
# Send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /home/nebula/nebula/uwsgi_params;
}
}
我的设置。
BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_URL = '/assets/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
STATIC_ROOT = os.path.join(BASE_DIR, "assets/")
STATICFILES_DIRS = ( os.path.join(BASE_DIR,'assets/'),)
这就是 静态是相同的,我将其复制以解决该问题):
assets demo.py media nebula.sock static uwsgi_params
db.sqlite3 manage.py nebula nebula_uwsgi.ini set store
这是“资产/”的内部:
admin css images jazzmin js vendor
This is my first real Django project and I am trying to configure it for production using NGINX and uWSGI. It is running on a Digital Ocean Ubuntu server. Everything is set up and working besides serving static CSS files. The strange thing about this is that its serving static images and JavaScript files fine, the only thing that isn't being served is the CSS.
This is what my site configuration file for NGINX looks like ('nebula' is the Ubuntu User and the name of the Django project):
# configuration of the server
server {
server_name example.com www.example.com;
charset utf-8;
# max upload size
client_max_body_size 75M;
# Django media and static files
location /media {
alias /home/nebula/nebula/media;
}
location /assets {
alias /home/nebula/nebula/assets;
}
# Send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /home/nebula/nebula/uwsgi_params;
}
}
This is what my Settings.py file looks like:
BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_URL = '/assets/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
STATIC_ROOT = os.path.join(BASE_DIR, "assets/")
STATICFILES_DIRS = ( os.path.join(BASE_DIR,'assets/'),)
This is what my base directory looks like (assets and static are the same, I duplicated it in an attempt to solve the issue):
assets demo.py media nebula.sock static uwsgi_params
db.sqlite3 manage.py nebula nebula_uwsgi.ini set store
This is inside of 'assets/':
admin css images jazzmin js vendor
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
nginx配置中静态文件的位置路径应匹配
static_url
设置The location path for your static files in your nginx config should match your
STATIC_URL
setting似乎这里可能有一个问题,
您可以尝试更改
为
Seems like there could be an issue here
Could you try Changing
to