请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

配置uwsgi后 无法加载静态文件

nginx:

upstream django {

# server unix:///path/to/your/mysite/mysite.sock; # for a file socket

server 127.0.0.1:8000; # for a web port socket (we'll use this first)

}

# configuration of the server


server {

# the port your site will be served on

listen      80;

# the domain name it will serve for

server_name 120.78.175.214 ; # substitute your machine's IP address or FQDN

charset     utf-8;


#root /home/hwkjWeb/dist; #定义服务器的默认网站根目录位置

#index index.html; #定义index页面

#error_page    404         /index.html; #将404错误页面重定向到index.html可以解决history模式访问不到页面问题


# max upload size

client_max_body_size 75M;   # adjust to taste


location = / {

    root /home/hwkjWeb/dist/;

    index index.html;

    error_page    404         /index.html;

    #uwsgi_pass  django;

    #include     uwsgi_params; # the uwsgi_params file you installed

}


location ~* \.html {

    root /home/hwkjWeb/dist/;

    index index.html;

    error_page    404         /index.html;

}


location / {

    proxy_pass http://django;

    proxy_set_header Host $http_host;

}

location ~* \.(css|js|jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|map|mp4|ogg|ogv|webm|htc)$ {

    root /home/hwkjWeb/dist/;

    index index.html;

    error_page    404         /index.html;

    expires 1M;

    access_log off;

    add_header Cache-Control "public";

}


location /public/ {

    alias /home/hwkjWeb/dist/;

}



# Django media

location /media {

    alias /home/hwkj/media/;  # 指向django的media目录

}


location /static {

    alias /home/hwkj/static/; # 指向django的static目录

}


# Finally, send all non-media requests to the Django server.

location /hwkj/ {

    uwsgi_pass  django;

    include     uwsgi_params; # the uwsgi_params file you installed

}

}

settings.py:

STATIC_URL = '/static/'


MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, "media")

STATIC_ROOT = os.path.join(BASE_DIR, "static")


uwsgi:

# mysite_uwsgi.ini file

[uwsgi]


# Django-related settings

# the base directory (full path)

chdir           = /home/hwkj

# Django's wsgi file

module          = hwkj.wsgi

# the virtualenv (full path)


# process-related settings

# master

master          = true

# maximum number of worker processes

processes       = 10

# the socket (use the full path to be safe

socket          = 127.0.0.1:8000

# ... with appropriate permissions - may be needed

# chmod-socket    = 664

# clear environment on exit

vacuum          = true

virtualenv = /root/.virtualenvs/hwkj

错误:

https://img1.sycdn.imooc.com//szimg/5b2750100001460411120379.jpg

正在回答 回答被采纳积分+3

1回答

bobby 2018-06-21 13:41:02

是否运行了collectstatic将所有静态文件放到了同一个目录之下?

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信