Location Snippets ignored when using Action.Return #5733
-
I want to expose a robots.txt endpoint. This can be done quiet easily with the Action.Return. Additionally I want to add CORS Headers. As there doesn't seem to be an option for this I am using location-snippets. The issue is that the location snippet is ignored. Heres the config:
The result using curl is:
It's simply missing within the rendered nginx.conf:
I did enable the location-snippets flag and it works when using the proxy option:
The location snippet is added to the nginx.conf
I couldn't find any corresponding log entries to this. And I tried version 3.1 and 3.5 and they both do not work. Can anybody help? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
What if the CORS was applied at the VS level and the action Proxy was applied using a VSR? |
Beta Was this translation helpful? Give feedback.
-
Hi @privateVoit, thanks for reporting. We believe this is a bug and plan to work on it. You can track progress here. |
Beta Was this translation helpful? Give feedback.
-
@privateVoit is this the result are you looking for? cc / @shaun-nx
apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
name: example.com
namespace: default
spec:
host: example.com
routes:
- path: /robots.txt
action:
return:
body: |-
User-agent: *
Disallow: /
code: 200
type: text/plain
location-snippets: |
add_header 'Cache-Control' 'private, max-age=0' always;
add_header 'Cross-Origin-Resource-Policy' 'cross-origin' always;
add_header 'X-Content-Type-Options' 'nosniff' always;
add_header 'X-Xss-Protection' '1; mode=block' always;
add_header 'X-Frame-Options' 'SAMEORIGIN' always;
add_header 'Frame-Options' 'SAMEORIGIN' always; kubectl apply -f vs-example.yaml inside the NIC container: nginx@nginx-ingress-7bb46c6c6-tjbxh:/etc/nginx/conf.d$ cat vs_default_example.com.conf
server {
listen 80;
listen [::]:80;
server_name example.com;
status_zone example.com;
set $resource_type "virtualserver";
set $resource_name "example.com";
set $resource_namespace "default";
server_tokens "on";
location @return_0 {
default_type "text/plain";
# status code is ignored here, using 0
return 0 "User-agent: *
Disallow: /";
}
location /robots.txt {
set $service "";
status_zone "";
add_header 'Cache-Control' 'private, max-age=0' always;
add_header 'Cross-Origin-Resource-Policy' 'cross-origin' always;
add_header 'X-Content-Type-Options' 'nosniff' always;
add_header 'X-Xss-Protection' '1; mode=block' always;
add_header 'X-Frame-Options' 'SAMEORIGIN' always;
add_header 'Frame-Options' 'SAMEORIGIN' always;
error_page 418 =200 "@return_0";
proxy_intercept_errors on;
proxy_pass http://unix:/var/lib/nginx/nginx-418-server.sock;
set $default_connection_header close;
}
} |
Beta Was this translation helpful? Give feedback.
Hi @privateVoit, thanks for reporting. We believe this is a bug and plan to work on it. You can track progress here.