0

So, I'm trying to do a very basic Nginx redirect from https://strnordicfin.eu/magnesium-fakta to https://strnordicse.eu/ntr/some/magnesium/ (just training domains, no worries).

My nginx-config looks like this,

worker_processes  1;
events { worker_connections  1024;
}
http {
server {
listen 80;
location https://strnordicfin.eu/magnesium-fakta {
rewrite   https://strnordicfin.eu/magnesium-fakta https://strnordicse.eu/ntr/some/magnesium/$request_uri  permanent;
}
}
}
  • but all this achieves is an error to pod and nginx 404 page,
[error] 19#19: *1 open() "/etc/nginx/html/magnesium-fakta" failed (2: No such file or directory), client: 10.244.10.130, server: , request: "GET /magnesium-fakta HTTP/1.1", host: "strnordicfin.eu"

I see that nginx is trying to open from pods /etc/nginx/html/magnesium-fakta, that is an empty directory, it should be getting it's info from https://strnordicse.eu/ntr/some/magnesium/.

Searching from net gives a lot of answers, but in those the server is mainly onsite not in a pod.

Edit: made some adjustments, nginx-config is now -

http {
server {
listen 80;
root /;
location https://strnordicfin.eu/magnesium-fakta/ {
return 302 https://strnordicse.eu/ntr/some/magnesium/magnesium-fakta/$request_uri;
}
}

the error message changed to -

[error] 20#20: *2 "/magnesium-fakta/index.html" is not found (2: No such file or directory), client: 10.244.8.172, server:

but still no redirect.

  • "open() "/etc/nginx/html/magnesium-fakta" failed" - OMG your document root is set to /etc/nginx/html - that's really bad. If you provisioned this docker instance then go fix it now. If you download random images off the innternet and run them then try a different one. – symcbean Jun 08 '23 at 13:37

1 Answers1

0

I see two problems here:

  1. Your document root root <path> is not set correctly. You should set it to a folder where your web files are present. For example, if you copy your files in /var/www/html while building your docker image, you should set it to root /var/www/html
  2. Your location block contains a URL whereas it should contain the matching pattern, like what you want to achieve when a matching pattern is found.

So based on your question, your final configuration should be something like this:

http {
  server {
  listen 80
  root /var/www/html;
  
  location ~* /magnesium-fakta {
    return 302 https://strnordicse.eu/ntr/some/magnesium/magnesium-fakta/$request_uri;
    }
  } 
}
faizan
  • 98
  • 4