There are two scenario that I'm trying to achieve.
Scenario A : If client request URL that contains .jpeg or .jpg file, redirect the user to a single .jpg file that are on the server in this case myimage.jpg
Scenario B : If client request URL that contains /abc/ directory, redirect the user to other domain through proxy while keeping the URL in tact.
Below is the content of my nginx.conf
http {
server {
listen 80;
root /usr/share/nginx/html;
#Scenario A
location ~* \.(jpg|jpeg){
rewrite ^(.*) http://$server_name/myimage.jpg last;
}
#Scenario B
location ^~ /abc/ {
proxy_pass http://cd.mycontent.com.my;
proxy_redirect localhost http://cd.mycontent.com.my;
proxy_set_header Host $host;
}
}
......
Most of it I referred to Nginx redirect to a single file The config does not contain error in /var/log/nginx/error.log but it does not perform as intended to.