Cloud Foundry-上下文路径路由显示404 Not Found页面

问题描述 投票:0回答:1

我想使用上下文路径路由来访问我要部署的应用程序。我希望用户仅通过使用以下URL即可访问该应用程序。

https://my-app.domain.int/foo

下面是Staticfile.txt文件的内容。

pushstate: enabled

下面是mainfest.yml文件的内容

---
applications:
 - name: my-app
   memory: 1G
   instances: 1
   path: .
   routes:
    - route: my-app.domain.int/foo
   buildpack: staticfile_buildpack

下面是目录结构。

dist
- index.html
- Staticfile.txt
- mainfest.yml

我尝试了以下解决方案,但没有帮助。

  1. Cloud Foundry map-route is not working when path mentioned
  2. Context routing for two different apps

访问URL时,出现404 Not Found页面。我想知道我是否想念任何东西。如何使上下文路径起作用。

[[注意:我正在使用Azure Pivotal PCF服务和Nginx服务器]

nginx cloudfoundry pivotal-cloud-foundry contextpath
1个回答
1
投票

只需将Staticfile.txt重命名为Staticfile(无扩展名)。


static_buildpack(在当前实现中)基于nginx.conf配置生成Staticfilehttps://docs.cloudfoundry.org/buildpacks/staticfile/index.html#staticfile

为了更好地理解,请尝试以下示例。

推送我的应用

  • my-app目录树:
- index.html # with title "root-index" 
- manifest.yml 
- Staticfile 
- public/ 
  - bar/
    - index.html # with title "bar-index"
  • manifest.yml
---
applications:
 - name: my-app
   routes:
   - route: my-app.example.com/foo
   - route: my-app.example.com/bar
   buildpacks: 
   - https://github.com/cloudfoundry/staticfile-buildpack.git # latest
  • Staticfile
root: public
pushstate: enabled

测试

-检查生成的nginx.conf

([cf ssh my-app cat /home/vcap/app/nginx/conf/nginx.conf

# [...] #
http { 
    # [...] #
    server { 
        listen 8080; 
        server_name localhost; 

        # Based on the Staticfile: "root: public"
        root /home/vcap/app/public;

        # Based on the Staticfile: "pushstate: enabled"
        if (!-e $request_filename) {
            rewrite ^(.*)$ / break;
        }

        location / { 
            index index.html index.htm Default.htm; 
        } 
        location ~ /\. { 
            deny all; 
            return 404; 
        } 
    } 
}   

-测试网址:

© www.soinside.com 2019 - 2024. All rights reserved.