django - 通过 Cloud Foundry 编辑 nginx.conf 文件
问题描述
我有一个使用 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;
}
}
}
解决方案
推荐阅读
- javascript - 在不应该出现的地方出现错误
- azure - Azure Blob 的数据集验证策略 minimumSizeMB
- discord - 在禁止/踢命令后发送消息
- reactjs - RCTLogInfo(来自 React/RCTLog)在哪里发送输出?
- python - 如何使用python计算LinkedList的节点数
- mysql - MySQL ERROR 1005 : 无法创建表 (errno: 150)
- html - VBA Web Scraping 使用 getElementsByClassName 获取名称和地址
- css - 如何在 b-col (bootstrap-vue) 元素中绑定自定义样式?
- system.reactive - RxNet TestScheduler 和 Windowing 没有达到我的预期
- c# - LiteDB - 选择具有一个 id 的多个条目