I have found out the problem.
The key point is the Apache DirectorySlash, if I visit https://outipaddress.com/theurl, apache will redirect to http://internalip.com:18080/theurl/ even if the X-Forword-* headers are set. I think it is a bug of apache httpd.
The workaround is to perform the redirect on nginx side.
`location /svn/ { if ($request_uri ~ "/[a-zA-Z0-9-_]+$") { rewrite ^ https://$server_name$request_uri/; } proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto https; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://internalip.com:18080; }`
Now nginx will redirect all urls that are not ended with slash and seem like a directory(contain only symbol characters).