2017-08-09 90 views
0

有靜態css的問題。我已經收集了靜音。如果運行Ubuntu服務器,Django 1.11.4,gunicorn,nginx找不到css文件

的CSS工作正常

./manage.py的runserver 0.0.0.0:8000

但如果運行

gunicorn --bind 0.0.0.0無法找到: 8000 hotel_main.wsgi:應用

與Dajango管理員相同的情況下

settings.py

STATIC_URL = '/static/' 
STATIC_ROOT = "/opt/static/" 
STATICFILES_DIRS = [ 
     ('static', os.path.join(BASE_DIR, 'hotel_site/static'),), 
     ('static', os.path.join(BASE_DIR, 'static'),), 
] 

Urls.py

from django.conf.urls import include, url 
from django.conf.urls.static import static 
from django.conf import settings 
from django.contrib import admin 

urlpatterns = [ 
    url(r'^admin/', admin.site.urls), 
    url(r'^ckeditor/', include('ckeditor_uploader.urls')), 
    url(r'^', include('hotel_site.urls')), 
] 

if settings.DEBUG: 
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 

Nginx的文件

upstream 78.155.199.17 { 
    server localhost:8000 fail_timeout=0; 
} 
server { 
     listen 80; 
     server_name 78.155.199.17; 
     return 301 78.155.199.17$request_uri; 
} 
server { 
     listen 80; 
     server_name 78.155.199.17; 
     location /static/ { 
       root /opt/; 
     } 
     location /media/ { 
       root /root/; 
     } 
     location/{ 
       proxy_set_header X-Forwarded-For 
       $proxy_add_x_forwarded_for; 
       proxy_redirect off; 
       proxy_pass 78.155.199.17; 
     } 
} 

項目樹

opt/ 
└─ static/ 
    ├─admin/ 
    ├─ckeditor/ 
    └─static/ 
    └─foundation/ 

root/ 
└─ ramn_hotel/ 

回答

相關問題