1

Have installed NGINX so I can divert

http://example.com/Dev/ to http://example.com:8080/apex/f?p=4550:1

I thought I found the solution and gave it a go:

Changed ngnix.config

   location /dev/ {
       rewrite ^/(/dev/)(.*)$ http://localhost:8080/apex/$1 break;
       rewrite_log on;
    }

.

sudo systemctrl reload nginx

But when I try http://example.com/Dev/ on a browser

I get the 500 error.

Website is listening to 8080 and NGiNX listening to 80

Also tried

location /dev {
    rewrite ^/dev(.*) /apex/$1 last;
    proxy_pass http://localhost:8080;
}
AndrewT
  • 468
  • 1
  • 8
  • 23

1 Answers1

2

Credit return 301

After reading the above answer I tried using return instead of rewrite and it worked.

Anyway here is what worked.

location ~ /dev/?$ {
        return 302 http://example.com:8080/apex/$1;
     }

After playing around I also got it to work with rewrite looks like I just needed to add a '~' in the location line

location ~ /dev {
           rewrite ^/dev(.*) http://example.com:8080/apex$1 last;
        }
AndrewT
  • 468
  • 1
  • 8
  • 23
  • 1
    Can anyone please explain what the '~' after the location command as it seemed to make the difference? – AndrewT Jun 11 '18 at 21:35
  • 1
    AndrewT: "If a tilde modifier is present, this location will be interpreted as a case-sensitive regular expression match." See [this link](https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms) – TFuto Jul 03 '20 at 10:44