문제

In Nginx, can 301 redirect URLs be grouped in an external file that can be included in the .conf file of the domain so that .conf is not modified each time a 301 redirect is needed?

Example:

A .nginx file, .redirects groups only 301 redirects:

location /test1 {
  rewrite ^ http://domain.com/test2 permanent;
}

Then, .redirects is included in the .conf file:

include /.redirects;

Can it work? (I've tested this and it didn't work for me.)

도움이 되었습니까?

해결책

It would work but you need to mind one thing, what context is this file going to be included to.

In your condition it's a location block, so you need to include it inside a server block, not http for example,

Also use full path not relative

server {
  # bla bla
  include /etc/nginx/.redirects;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top