whats the frequency of the letter : in:
q: how to block in nginx requests with no referral i have a site that is used with no permission by someone inside an mobile app , because i have noticed an big increase in direct android users with no referrals.
i have tried to block access to the directory like this :
location /widget/link/ {  if ($http_referer = ) {  return 403; } }


but i have noticed that the api dosent work for the rest of the visitors with referral because they get 404 , with this error in the logs
2019/08/11 12:22:27 [error] 1914#1914: *2417 /home/site/public/widget/link/index.html is not found (2: no such file or directory), client: 2.44.127.232, server: domain.com, request: get /widget/link/?link=https://example.com


i want to protect against someone else using my site inside an mobile app
how do i block all chrome mobile users with no referral to /widget/link/ ?
my nginx conf is here
        server_name domain.com;
        root /home/domain/public/;
index index.html index.htm index.php;


  location ~ \.php$ {
            try_files $uri =404;
            include /etc/nginx/fastcgi_params;
                 fastcgi_pass unix:/run/php/php7.0-fpm.sock;
           fastcgi_index index.php;
            fastcgi_param script_filename $document_root$fastcgi_script_name;



   }
  location ~ ^/(assets|images|javascripts|stylesheets|system)/ {
      gzip_static on;
      expires     max;
      add_header  cache-control public;
      add_header  last-modified ;
      add_header  etag ;
      # open_file_cache          max=1000 inactive=500s;
      # open_file_cache_valid    600s;
      # open_file_cache_errors   on;
      domain;
  }




       location / {



 try_files $uri $uri/ /index.php?$query_string;



}



a: have a look at if is evil. to recap it: you shouldnt be using if inside location.
the if directive can be safely used only directly in the server {} context, if its anywhere else then youre asking for troubles.
youll have to write the conditional logic using map for the most part, and then use if within the safe context. heres how.
first, define your maps within http {} (typically, in nginx.conf). the variable names are self-explanatory:
http {
    map $http_user_agent $is_android {
      default 0;
      ~android 1;
    }

    map $http_referer $has_referer {
        default 0;
        ~.      1;
    }

    map $is_android:$has_referer $bad_client {
        default 0;
        1:0     1;
    }
    ...
}

now we have the desired variable $bad_client available for use with if so you can apply restriction on bad clients like so:
server {
    if ($bad_client) {
        return 403; 
    }
    ...
}

to test:
curl -il https://example.com/ -h user-agent: android # will get 403
curl -il https://example.com/ -h user-agent: android -h referer: foo # will get 200


user
In that passage, there are 23 occurrences of the letter ":."
assistant