400 bad requeat. The plain HTTP request was sent to HTTPS port

i set up nextcloud 16 in a docker from docker-compose file download from here(https://github.com/nextcloud/docker/tree/master/.examples/docker-compose/with-nginx-proxy-self-signed-ssl/mariadb/fpm) and change the reverse proxy listening port from 80/443 to 8080/8443 via a new commit of nginx-proxy (https://github.com/jwilder/nginx-proxy/commit/f4fd455bdfa14272b6536d3257c82a9865c8c485), because the host also has webui which has occupied port 80 and 443.
The host server is an NAS in a LAN, whose ip is like, and the net gate ( router) can be access from Internet with a domain name resolved to the public IP signed to the router.
The nextcloud can be accessed from Internet through dmz or port forwarding. http auto redirect to https, and https:// domain:8443 also works fine.
But have some problem when accessing NC through private IP.
when using, browser auto redirect to 8443 port, but no https in the front of the url, so the error “400 bad request. The plain HTTP request was sent to HTTPS port400” occurred. This error also occurred when using, I can see the login page, but after login https also became http.
I tried to set X_Forwarded_Proto to https in nginx config file and reload nginx in the proxy container, it doesn’t solve the problem.
May it is not related with nginx proxy?
any suggestions or help will be thankful!