【问题标题】:Cloud Foundry - Context path routing shows 404 Not Found pageCloud Foundry - 上下文路径路由显示 404 Not Found 页面
【发布时间】:2020-02-04 12:11:09
【问题描述】:

我想使用上下文路径路由来访问我尝试部署的应用程序。我希望用户只能使用以下 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 cloud-foundry contextpath


    【解决方案1】:

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


    static_buildpack(在当前实现中)根据Staticfile 配置生成nginx.confhttps://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-appcat /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; 
            } 
        } 
    }   
    

    - 测试网址:

    【讨论】:

    • 谢谢,只是将 Staticfile.txt 重命名为 Staticfile 帮助了我
    猜你喜欢
    • 1970-01-01
    • 2017-08-08
    • 2020-11-22
    • 2015-01-07
    • 1970-01-01
    • 1970-01-01
    • 2018-12-03
    • 2020-07-23
    • 1970-01-01
    相关资源
    最近更新 更多