我想将某个子目录的所有条目重定向到另一个(外部)域,其中包含地址的“其余部分”。我尝试了一些方法,但没有效果...
server {
listen [::]:443 ssl;
listen 443 ssl;
server_name cahiers.example.fr cahiers.example.eu.org;
return 301 https://publications.example.fr/cahiers;
ssl_certificate /etc/letsencrypt/live/publications.example.fr/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/publications.example.fr/privkey.pem; # managed by Certbot
}
# Bloc pour la redirection vers le HTTPS.
server {
location ^~ /subdir(.*) {
return 301 https://external.org/$1;
}
if ($host = cahiers.example.fr) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = cahiers.example.eu.org) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name cahiers.example.fr cahiers.example.eu.org;
return 301 https://$host$request_uri;
}
我究竟做错了什么?
谢谢
答案1
您已将重定向放在 HTTP 块中。请将其放在 https 块中,例如多于它目前位于哪里。
server {
listen [::]:443 ssl;
listen 443 ssl;
server_name cahiers.example.fr cahiers.example.eu.org;
return 301 https://publications.example.fr/cahiers;
ssl_certificate /etc/letsencrypt/live/publications.example.fr/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/publications.example.fr/privkey.pem; # managed by Certbot
location ^~ /subdir(.*) {
return 301 https://external.org/$1;
}
}