Tuesday, August 30, 2022

Nginx location Regex Expression

 Nginx Regex Expression

Nginx location block allow you to route request to particular location in file system or particular url.

Below example is to show how to route domain name and number to domain.com:port.

server {

  listen 80;

  server_name anup.co.in;

  root /usr/share/nginx/html;

   location ~ "/app/lck/([a-z0-9\-\.]+)/([0-9]+)" {

      return 301 http://$1:$2;



    Above highlighted part will redirect as follows -

http://anup.co.in/app/lck/google.com/8080  --> http://google.com:8080

No comments: