静态文件未在AWS Lightsail上提供 [英] Static files not being served on AWS Lightsail

查看:60
本文介绍了静态文件未在AWS Lightsail上提供的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试了两本教程的两天后,阅读StackOverflow,我正在寻求帮助!

After 2 days of trying multiple tutorials & reading StackOverflow, I'm calling for help!

设置:开发版本在AWS Lightsail服务器上运行平稳.在生产部署期间,我一直在遇到静态文件的连续问题.该应用程序在指定的子域上运行,但是缺少所有的JS/CSS/images/...

The setting: The development version is running smoothly on the AWS Lightsail server. It's during the production deployment that I'm running in continuous problems with the static files. The application runs on the appointed subdomain but it's missing all the JS/CSS/images/...

我一直关注官方文档,但无济于事.1/ https://docs.bitnami.com/aws/infrastructure/django/get-started/deploy-django-project/2/ https://docs.bitnami.com/aws/infrastructure/django/get-started/deploy-django-project/

I have followed the official docs but to no avail. 1/ https://docs.bitnami.com/aws/infrastructure/django/get-started/deploy-django-project/ 2/ https://docs.bitnami.com/aws/infrastructure/django/get-started/deploy-django-project/

带有相关文件的我的文件夹树":

Project
    - conf
       - httpd-app.conf
       - httpd-prefix.conf
    - Django2Tutorial
      - settings.py
      - wsgi.py
    - Solar
        - static
    - static (after running collectstatic function in terminal,-it includes the admin, Solar statics)

我的设置:

STATIC_ROOT = os.path.join(BASE_DIR,'static')
STATIC_URL = '/static/'
DEBUG = False
ALLOWED_HOSTS = ['54.169.172.***']

wsgi.py文件

import os
import sys
sys.path.append('/opt/bitnami/apps/django/django_projects/Project')
os.environ.setdefault("PYTHON_EGG_CACHE", "/opt/bitnami/apps/django/django_projects/Project/egg_cache")
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'DjangoTutorial2.settings')
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

我的conf文件:

1.httpd-app.conf文件

<IfDefine !IS_DJANGOSTACK_LOADED> 
Define IS_DJANGOSTACK_LOADED
WSGIDaemonProcess wsgi-djangostack   processes=2 threads=15    display-name=%{GROUP}
</IfDefine> 

<Directory "/opt/bitnami/apps/django/django_projects/Project/DjangoTutorial2">

    Options +MultiViews
    AllowOverride All
    <IfVersion >= 2.3>
        Require all granted
    </IfVersion>
    
    WSGIProcessGroup wsgi-djangostack

    WSGIApplicationGroup %{GLOBAL}
                    
</Directory>

Alias /static "/opt/bitnami/apps/django/django_projects/Project/static"
<Directory "/opt/bitnami/apps/django/django_projects/Project/static">
Require all granted  
</Directory>

WSGIScriptAlias /  '/opt/bitnami/apps/django/django_projects/Project/DjangoTutorial2/wsgi.py'

2.httpd-prefix.conf文件

# Include file
RewriteEngine On
RewriteCond "%{HTTP_HOST}" ^ec2-([0-9]{1,3})-([0-9]{1,3})-([0-9]{1,3})-([0-9]{1,3})\..*\.amazonaws.com(:[0-9]*)?$
RewriteRule "^/?(.*)" "%{REQUEST_SCHEME}://%1.%2.%3.%4%5/$1" [L,R=302,NE]
Include "/opt/bitnami/apps/django/django_projects/Project/conf/httpd-app.conf"

所做的其他调整:(/opt/bitnami/apache2/conf/bitnami)1/bitnami-apps-prefix.conf文件

Other adjustments made: (/opt/bitnami/apache2/conf/bitnami) 1/ bitnami-apps-prefix.conf file

Include "/opt/bitnami/apps/django/django_projects/Project/conf/httpd-prefix.conf"

2/bitnami.conf文件

2/ bitnami.conf file

VirtualHost _default_:80>
    WSGIScriptAlias / /opt/bitnami/apps/django/django_projects/Project/DjangoTutorial2/wsgi.py
<Directory /opt/bitnami/apps/django/django_projects/Project>
    AllowOverride all
Require all granted
Options FollowSymlinks
    </Directory>
DocumentRoot /opt/bitnami/apps/django/django_projects/Project
</VirtualHost>

  1. bitnami-apps-vhosts.conf文件为空?可以吗?

也已检查:

  • 多次重启Apache
  • 使用static_url&static_roots

任何人都可以建议如何进行吗?哈哈2天了,真让人沮丧.

Can anyone advise how to proceed? It's been extremely frustrating 2 days haha.

注意,也许这可以帮助您:使用findstatic函数仔细检查,它将我重定向到Solar/static文件夹.我以为自从我运行了静态收集之后,我应该指向apache conf&中的项目级别静态文件夹.不是Solar level静态文件夹.

Note, maybe this can help : double-checked with the findstatic function, it redirects me to the Solar/static folder. I thought since I ran collect static, I should point to the Project level static folder in the apache conf & not the Solar level static folder.

推荐答案

您需要将 Alias/static//opt/bitnami/apps/django/django_projects/Project/static/添加到您的虚拟主机中config,以便服务器知道将/static/请求映射到该文件夹​​.

You need to add Alias /static/ /opt/bitnami/apps/django/django_projects/Project/static/ to your virtualhost config so the server knows to map /static/ requests to that folder.

这篇关于静态文件未在AWS Lightsail上提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆