Nginx 301 redirect makes it impossible to backup

Hello Im going crazy here with a https problem on one of my virtual servers (main with usermin and webmin login) I cant get the https to work on default. I have tryied every setup that i could find on the net. Finally with a redirect 301 i managed to get it working. however then webmin cant backup the server or sub because of some server config conflict that Nginx creates. And if I put in the 301 in the listening I get a to many redirects in browser wich then fails to load page :(

This is my working setup but with no backup unfortunately- Really hope some of you could help figuring this out :( on my second server every request is going to https even without a 301 in config?

Nginx config for my.virtualserver.com

server { server_name sub.hostname.tld www.sub.hostname.tld; listen serverip:80; rewrite ^/(.*) https://sub.hostname.tld/$1 permanent; }
server {
server_name sub.hostname.tld www.sub.hostname.tld;
listen serverip; #rewrite ^/(.*) https://sub.hostname.tld/$1 permanent;   <--- without # here and # in first lines make a browser fail with to many redirections
root /home/hostname/domains/sub.hostname.tld/public_html;
index index.html index.htm index.php;
access_log /var/log/virtualmin/sub.hostname.tld_access_log;
error_log /var/log/virtualmin/sub.hostname.tld_error_log;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME /home/hostname/domains/sub.hostname.tld/public_html$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT /home/hostname/domains/sub.hostname.tld/public_html;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param HTTPS $https;
location / {
proxy_pass https://myhostname.tld:2087/;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass localhost:8001;
}
listen serverip:443 ssl;
ssl_certificate /home/mydir/ssl.cert;
ssl_certificate_key /home/mydir/ssl.key;
#ssl off;

}
Status: 
Active

Comments

What error are you getting when trying to backup exactly?

Creating backup for virtual server sub.domain.tld ..

    Copying virtual server configuration ..
    .. done

    Copying records in DNS domain ..
    .. done

    Saving mail aliases ..
    .. done

    Saving mail and FTP users ..
    .. done

    Backing up mail and FTP user Cron jobs ..
    .. none to backup

    Copying Logrotate configuration ..
    .. done

    Backing up Nginx webserver configuration ..
    .. no virtual host named sub.domain.tld exists

    Backup failed! See the progress output above for the reason why.

It does the same for every sub or server with the 301 in config

Really hope some one could help me sorting this one out- it would be great to have the backup enabled on all servers.

I can see in virtual server list the server name is set to standard. So i have tryied to remove all spaces wich then ofcourse give me two servers with same name. However this fixes the "no virtualhost name" but then i get to many redirects. :(