简体   繁体   English

使用 nginx gunicorn 在 digitalocean 上部署 django react

[英]deploying django react on digitalocean with nginx gunicorn

i have bind react build inside django.我在 django 中绑定了反应构建。 its working fine on localhost but on server its static files not working.它在本地主机上工作正常,但在服务器上它的静态文件不起作用。 when i run this after activating virtualenv:当我在激活 virtualenv 后运行它时:

gunicorn --bind 64.225.24.226:8000 liveimage.wsgi

its admin panel working without css:它的管理面板在没有 css 的情况下工作: 管理面板

this is my nginx default config:这是我的 nginx 默认配置:

server {
listen 80;
server_name 64.225.24.226;

access_log off;
location /media/ {
alias /root/liveimage/media/;  # change project_name
 }
location /static {
 autoindex on;
 alias /root/liveimage/build;
}
location / {
    proxy_pass http://127.0.0.1;
    proxy_set_header X-Forwarded-Host $server_name;
    proxy_set_header X-Real-IP $remote_addr;
    add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
}

} }

my seetings.py:我的seetings.py:

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, 'build')],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
            'social_django.context_processors.backends',
            'social_django.context_processors.login_redirect',
        ],
    },
},
]

STATICFILES_DIRS = [os.path.join(BASE_DIR, 'build/static')] 


STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

gunicorn.service: gunicorn.service:

[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/root/liveimage
ExecStart=/root/venv/bin/gunicorn \
      --access-logfile - \
      --workers 3 \
      --bind unix:/run/gunicorn.sock \
      liveimage.wsgi:application
 [Install]
 WantedBy=multi-user.target

my project is in /root/liveimage and virtualenv at /root/venv i dont know what going wrong我的项目在 /root/liveimage 和 virtualenv 在 /root/venv 我不知道出了什么问题

Gunicorn will not show styling. Gunicorn 不会显示样式。

I found this :我找到了这个 :

Note: The admin interface will not have any of the styling applied since Gunicorn does not know how to find the static CSS content responsible for this.注意:管理界面不会应用任何样式,因为 Gunicorn 不知道如何找到对此负责的静态 CSS 内容。

From the docs文档

I don't really know Nginx configuration, but the key here is that Django doesn't serve static files in production, they must be served by Nginx.我真的不知道 Nginx 的配置,但这里的关键是 Django 在生产中不提供静态文件,它们必须由 Nginx 提供。

On your site, go to your browser's dev tools -> network -> click css, and look at the urls.在您的站点上,转到浏览器的开发工具 -> 网络 -> 单击 css,然后查看 url。 They must target the static directory generated by manage.py collectstatic and Nginx must serve the content of that directory from those urls.它们必须以manage.py collectstatic生成的静态目录为目标,而 Nginx 必须从这些 url 提供该目录的内容。

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

相关问题 在Gunicorn / Nginx上部署Django站点时出现JS / Jquery问题(在DigitalOcean上) - JS/Jquery issue when deploying Django site on with Gunicorn/Nginx (on DigitalOcean) Gunicorn 未在 django react nginx 配置 digitalocean 中加载反应前端 - Gunicorn not loading react frontend in django react nginx configuration digitalocean 使用gunicorn和nginx部署Django - Deploying Django with gunicorn and nginx DigitalOcean使用Nginx和Gunicorn将域添加到Django实例 - DigitalOcean add domain to django instance with nginx and gunicorn 使用 Gunicorn 和 nginx 部署 Django 项目 - Deploying Django project with Gunicorn and nginx 使用 Nginx、Gunicorn 和 Supervisor 部署 Django - Deploying Django with Nginx, Gunicorn and Supervisor 使用 Selenium 和 Django 的带有 DigitalOcean (gunicorn/nginx) 的 502 Bad Gateway - 502 Bad Gateway with DigitalOcean (gunicorn/nginx) using Selenium and Django Django Nginx Gunicorn - 媒体文件未显示(DigitalOcean 部署) - Django Nginx Gunicorn - Media Files Not Showing (DigitalOcean Deployment) 为 DRF、Django 和 React 前端配置 Nginx 和 Gunicorn - Configuring Nginx and Gunicorn for DRF, Django and React Frontend 使用Nginx和Gunicorn将Django应用程序部署到AWS EC2 - Deploying Django app to AWS EC2 using Nginx and Gunicorn
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM