map $request_uri $new_uri {
# fix published urls
/wrong-path "https://${host}/correct-path";
# force https for others
default "https://${host}${request_uri}";
}
server {
listen [::]:80 default_server;
listen 80 default_server;
server_name _;
return 301 $new_uri;
}
docker run --detach --name nginx-redirect \
--volume "${PWD}/redirect.conf:/etc/nginx/conf.d/default.conf" \
--publish "8080:80" \
--workdir "/usr/share/nginx/html/" \
nginx
curl -SsD- http://localhost:8080/
curl -SsD- -H "Host: www.example.com" http://localhost:8080/wrong-path
curl -SsD- -H "Host: www.example.com" http://localhost:8080/others
docker stop nginx-redirect
docker rm nginx-redirect