nginxcloud-foundrycontextpath

Cloud Foundry - Context path routing shows 404 Not Found page


I want to use context path routing to access the app that I am trying to deploy. I want the users to access the app only by using the below URL.

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

Below is the Staticfile.txt file content.

pushstate: enabled

Below is the mainfest.yml file content

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

Below is the directory structure.

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

I have tried the following solutions but it didn't help.

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

When I access the URL, I get 404 Not Found page. I want to know if I am missing anything. How can I get the context path to work.

[Note: I am using Azure Pivotal PCF service and nginx server]


Solution

  • Just rename Staticfile.txt to Staticfile (without extension).


    The static_buildpack (in current implementation) generates nginx.conf based on Staticfile configuration: https://docs.cloudfoundry.org/buildpacks/staticfile/index.html#staticfile

    For better understanding try the example below.

    Push the my-app

    - index.html # with title "root-index" 
    - manifest.yml 
    - Staticfile 
    - public/ 
      - bar/
        - index.html # with title "bar-index"
    
    ---
    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
    
    root: public
    pushstate: enabled
    

    Test it

    - Check the generated 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; 
            } 
        } 
    }   
    

    - Test the urls: