简体   繁体   English

Nginx中的静态文件,Django中的Gunicorn

[英]Static files in Nginx, Gunicorn in Django

i have try every configuration that i found and the static files don't get loaded, so i doesn't know what's wrong. 我已经尝试了我发现的所有配置,并且没有加载静态文件,所以我不知道出了什么问题。 I create the app using Pycharm. 我使用Pycharm创建应用程序。

Can someone give me a hand to fix this? 有人可以帮我解决这个问题吗?

Here are the configurations. 这是配置。

settings.py settings.py

MEDIA_ROOT = ''
MEDIA_URL = '/Users/gcarranza/PycharmProjects/clouddemyTest/'

STATIC_ROOT = ''
STATIC_URL = '/Users/gcarranza/PycharmProjects/clouddemyTest/static/'

STATICFILES_DIRS = (
'/Users/gcarranza/PycharmProjects/clouddemyTest/static',)

nginx conf: nginx conf:

server {
    listen       80;
    server_name  localhost;

    location /static/ {
        autoindex on;
        alias   /Users/gcarranza/PycharmProjects/clouddemyTest/static/; 
    } 
    location / {
        proxy_pass http://127.0.0.1:8000;
    }
}

Gunicorn: 独角兽:

gunicorn_django -b localhost:8000

You got the root and url backwards. 您获得了根目录并向后url。 Should be: 应该:

STATIC_ROOT = '/Users/gcarranza/PycharmProjects/clouddemyTest/static/'
STATIC_URL = '/static/'

And same for media 和媒体一样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM