I have two url
http://localhost/?shop=test
http://localhost/login?shop=test
first url is working. But second url coming 404 nginx page. how can I fix this problem. I want to every location come header if exist shop query
server {
listen 8081 default_server;
listen [::]:8081 default_server;
server_name _;
location / {
if ( $arg_shop ) {
add_header Content-Security-Policy "frame-ancestors https://$arg_shop";
}
root /home;
index index.html;
include /etc/nginx/mime.types;
try_files $uri $uri/ /index.html?$query_string;
}
}
2
Answers
I fixed like that
The problem with using
if
inside alocation
, is that it doesn’t work the way you expect.You can use a
map
to define the value of theadd_header
directive. If the argument is missing or empty, the header will not be added.For example: