【发布时间】:2020-06-19 21:49:09
【问题描述】:
我在 Cloud Foundry 中使用以下 manifest.yml 文件将 Django/Gunicorn + whitenoise(用于静态文件服务)作为单个应用程序工作:
---
applications:
- name: mydjango
instances: 1
command: src/tvpv_portal/bin/start_gunicorn_django.sh
memory: 2048M
disk_quota: 1024M
buildpacks:
- https://github.com/cloudfoundry/python-buildpack.git
stack: cflinuxfs3
env:
DJANGO_MODE: Production
为了学习/实验,我想删除白噪声并使用 nginx_buildpack 设置 Nginx 以与 Django/Gunicorn 一起使用。但是,我不确定如何在单个应用程序上使用多个构建包。我按照https://docs.cloudfoundry.org/buildpacks/nginx/index.html 的指示在我的项目目录中创建了nginx.conf、mime.types 和buildpack.yml。
nginx.conf
daemon off;
error_log /home/vcap/app/nginx-error.log;
events { worker_connections 1024; }
http {
log_format cloudfoundry '$http_x_forwarded_for - $http_referer - [$time_local] "$request" $status $body_bytes_sent';
access_log /home/vcap/app/nginx-access.log cloudfoundry;
default_type application/octet-stream;
include mime.types;
sendfile on;
gzip on;
tcp_nopush on;
keepalive_timeout 30;
port_in_redirect off; # Ensure that redirects don't include the internal container PORT - 8080
server {
listen {{port}};
server_name localhost;
# Serve static files.
location /static/ {
alias /home/vcap/app/src/tvpv_portal/static/;
}
# Serve media files.
location /media/ {
alias /home/vcap/app/src/tvpv_portal/media/;
}
# Reverse proxy to forward to main app.
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1:8000;
}
}
}
我试着做cf push mydjango -b nginx_buildpack -b python_buildpack。但是从查看文档看来,只有最后一个 buildpack 能够启动该命令。前面的 buildpack 中的命令将被忽略。因此,我无法启动 nginx 服务器。如何正确设置多个 buildpack?
我确实阅读了CloudFoundry: nginx for serving static content on top of Gunicorn (Docker),但回复是关于拥有两个具有不同路线的独立应用程序。由于这更多地用于使用 CF 进行学习/实验,我想知道是否可以使用单个应用程序来完成它而不分离静态内容。感谢您的帮助。
【问题讨论】:
-
我将尝试使用两个应用程序进行试验。一个用于 nginx。一个用于 Django/Gunicorn,让它们通过自己的域地址相互交谈。
标签: django nginx cloud-foundry