AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-622750

Fernando Tholl's questions

Martin Hope
Fernando Tholl
Asked: 2021-03-17 13:54:07 +0800 CST

使用 Python、Apache(代理)和 SSL 的静态文件 [重复]

  • 0
这个问题在这里已经有了答案:
如何向 apache 反向代理规则添加例外 [重复] 1 个回答
去年关闭。

这是我在社区的第一个问题,如果我写错了,我提前道歉

我在 Python (Django) 中开发了一个应用程序,并且在质量环境中我使用 gunicorn 来提供部署:gunicorn --bind 0.0.0.0:8000 application.wsgi --daemon

在同一台服务器上,我使用 Apache 监听端口 443 (https://) 并通过代理将请求重定向到 Gunicorn,如下所示:

  <VirtualHost *:443>
  
        ServerName example.com   

        ProxyRequests Off
        ProxyPreserveHost On
        
        <Proxy *>
                Require all granted
                Allow from all
        </Proxy>

        ProxyPass / http://example.com:8000/
        ProxyPassReverse / http://example.com:8000/

        # SSL
        SSLEngine On

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        #Include conf-available
        SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf

</VirtualHost>

一切正常,我可以通过 https 访问它,除了静态文件。

我按照文档的建议,执行了命令collectstatic,文件是在我在 settings.py 中配置的文件夹(/static)中生成的

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

我利用了我已经安装了 Apache 的优势,我尝试在同一个 VirtualHost 中添加 /static 目录的别名,如下所示:

Alias /static "/home/ubuntu/example/static/"
<Directory "/home/ubuntu/example/static">
      Order allow,deny  
      Allow from all
      Require all granted
</Directory>

VirtualHost 的完整配置如下所示:

 <VirtualHost *:443>
  
        ServerName example.com  

        Alias /static "/home/ubuntu/example/static/"
        <Directory "/home/ubuntu/example/static">
              Order allow,deny  
              Allow from all
              Require all granted
        </Directory>

        ProxyRequests Off
        ProxyPreserveHost On
        
        <Proxy *>
                Require all granted
                Allow from all
        </Proxy>

        ProxyPass / http://example.com:8000/
        ProxyPassReverse / http://example.com:8000/

        # SSL
        SSLEngine On

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        #Include conf-available
        SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf

</VirtualHost>

但是,当尝试访问此目录中的文件时,我总是得到一个:

未找到 - 在此服务器上未找到请求的资源。

我分析了 error.log 和 access.log,甚至没有在日志中点击请求。

将相同的别名添加到端口 80 上的另一个虚拟主机,它可以正常工作。我认为问题在于将此别名添加到端口 443 的特定 VirtualHost

你能帮助我吗?

django python apache2 gunicorn
  • 1 个回答
  • 700 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve