【发布时间】:2020-09-24 15:21:14
【问题描述】:
我有一个使用 django、angular 构建并使用 cloudfoundry 托管的应用程序。 带有 http 的部分 URL 无法继续,例如 http://www.example.com/home 会失败,但 https://www.example.com/home 会正常工作。
同样的方式http://www.example.com 将重定向到https://www.example.com,但是当给出半个 URL 时,重定向失败。
所以我对这个问题做了一些研究,发现 nginx.conf 文件需要编辑,找不到更多。是否需要与 django 应用程序一起上传到 cloud Foundry
任何关于这方面的指南都会非常有帮助 CF PUSH 输出:
C:\***\dcms-api>cf push -b https://github.com/cloudfoundry/nginx-buildpack.git
Pushing from manifest to org DCMS / space Development as ***@***.com...
Using manifest file C:\***\dcms-api\manifest.yml
Getting app info...
Updating app with these attributes...
name: dcms
path: C:\***\dcms-api
buildpacks:
https://github.com/cloudfoundry/nginx-buildpack.git
disk quota: 512M
health check type: port
instances: 1
memory: 256M
stack: cflinuxfs3
env:
ACCEPT_EULA
DB_HOST
DB_NAME
DB_PORT
DB_USER
DB_USER_PASSWORD
SYS_NAME
SYS_PASSWORD
routes:
dcms***.com
Updating app dcms...
Mapping routes...
Comparing local files to remote cache...
Packaging files to upload...
Uploading files...
385.10 KiB / 385.10 KiB [=====================================================================] 100.00% 1s
Waiting for API to complete processing files...
Staging app and tracing logs...
Cell 9c6ffac8- creating container for instance eb1fe223-
Cell 9c6ffac8- successfully created container for instance eb1fe223-
Downloading app package...
Downloading build artifacts cache...
Downloaded app package (2M)
Downloaded build artifacts cache (108M)
-----> Download go 1.12.4
-----> Running go build supply
/tmp/buildpackdownloads/adf6125a52c1a65c9523985b5a87ec38 ~
-----> Nginx Buildpack version 1.1.9
-----> Supplying nginx
-----> No nginx version specified - using mainline => 1.17.10
-----> Installing nginx 1.17.10
Download
[https://buildpacks.cloudfoundry.org/dependencies/nginx/nginx_1.17.10_linux_x64_cflinuxfs3_2fe87dae.tgz]
**WARNING** nginx 1.17.x will no longer be available in new buildpacks released after 2020-05-01.
See: https://nginx.org/
**ERROR** nginx.conf file must be configured to respect the value of `{{port}}`
**ERROR** Could not validate nginx.conf: no {{port}} in nginx.conf
Failed to compile droplet: Failed to run all supply scripts: exit status 14
Exit status 223
Cell 9c6ffac8- stopping instance eb1fe223-
Cell 9c6ffac8- destroying container for instance eb1fe223-
Cell 9c6ffac8- successfully destroyed container for instance eb1fe223-
Error staging application: App staging failed in the buildpack compile phase
FAILED
我对在哪里放置以下 nginx.conf 有疑问?
nginx.conf:
worker_processes 1;
daemon off;
events { worker_connections 1024; }
http {
log_format cloudfoundry '$http_x_forwarded_for - $http_referer - [$time_local] "$request" $status $body_bytes_sent';
default_type application/octet-stream;
include mime.types;
sendfile on;
gzip on;
tcp_nopush on;
keepalive_timeout 30;
server {
listen 8080;
server_name apps1-bg-int.icloud.intel.com .apps1-bg-int.icloud.intel.com;
location / {
root /home/vcap/app/static/UI;
index index.html;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
}
}
}
【问题讨论】:
-
您使用的是哪个构建包?还请为您的应用提供
cf push的完整输出。这将告诉我们更多关于为您的应用程序部署的内容。通常对于 Python 应用程序,您不需要/没有 Nginx。 -
我的建议是查看重定向的来源。检查您的域名注册商,有时他们会提供重定向服务。另外,检查您的应用程序。应用程序通常会启动这些重定向,但它可能做错了。您的应用程序将位于至少一层代理之后,因此它需要查看 x-forwarded-port 或 x-forwarded-proto 标头来做出决定。我没有用 Django 做到这一点,但我确信有办法。在反向代理后面并需要处理这些标头是一种常见的部署。希望有帮助!
标签: django nginx angular6 cloud-foundry