0

I have a website which performs proxy pass and I want to block some sub path access and not sure how can I do this. Following is the nginx conf file snippet:

server {
    root           /usr/share/nginx/html;
    server_name testnginx.com www.testnginx.com;

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/testnginx.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/testnginx.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

  location ~* /ng\/f\?p {
      return 404;
   }

  location / {
    rewrite ^/$ /ng/testnginx/r/100/home permanent;
  }

 location /ng/ {
    proxy_pass https://127.0.0.1:2000/ng/;
    # set Origin to blank to avoid Chrome problems with CORS
    proxy_set_header Origin "" ;

    # pass along some header variables with the public host name/port/and so on
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Host $host:$server_port;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
  }

 }


I want to redirect all the subpath such as /ng/f?p to /ng/testnginx/r/100/home but it is not working for me.

drifter
  • 389
  • 1
  • 5
  • 17
  • `?p` is a query part of request URI and cannot be checked with the `location` directive. You need to check the `$args` internal nginx variable if you want to behave differently depending of a HTTP request query parameters. – Ivan Shatsky Jun 11 '20 at 20:42
  • See [this answer](https://stackoverflow.com/questions/54329332/nginx-redirect-url-with-query-strings/54330947#54330947). – Richard Smith Jun 12 '20 at 07:36

0 Answers0