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.
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]
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.
my-app
directory tree:- 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;
}
}
}
root-index
because /public/foo/index.html
doesn't existbar-index
because /public/bar/index.html
existsroot-index
because /public/bar/non-existent.html
doesn't exist