Trying to use nxing instead of url rewriter

Hello! We had issue with url rewriter and now trying to add rule in nginx config to hide /bin/ part from url, but it ruins site every time.
my config:

server {
    listen 80;
    server_name _;
    return 404;
}

server {
    listen 443;
    ssl_certificate /etc/nginx/ssl/***.crt;
    ssl_certificate_key /etc/nginx/ssl/***.key;
    server_name _;
    return 404;
}

server {
    listen 80;
    server_name deploy.community.office;
    underscores_in_headers on;
    proxy_http_version 1.1;
    proxy_buffering off;

    location ~ ^/bin/(.*)$ {
        rewrite ^/bin/(.*)$ /$1 permanent;
    }

    rewrite ^(.*) https://$host$1 permanent;
}

server {
    listen 443 ssl;
    ssl_certificate /etc/nginx/ssl/***.crt;
    ssl_certificate_key /etc/nginx/ssl/***.key;

    underscores_in_headers on;
    proxy_buffering off;
    server_name deploy.community.office;
    client_max_body_size 0;
    proxy_connect_timeout       6000;
    proxy_send_timeout          6000;
    proxy_read_timeout          6000;
    send_timeout                6000;

    location ~ ^/bin/(.*)$ {
        rewrite ^/bin/(.*)$ /$1 permanent;
    }

    location  / {
        proxy_pass_request_headers      on;
        proxy_pass http://xwiki-experimental:8080;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Scheme $scheme;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

any idea why it happening? and how to fix it? thank you

i tried alot of options of config, only this one saves CSS of site and almost all links, but search, notification windows and some links to video still doesnt work, this is config file:

server {
    listen 80;
    server_name _;
    return 404;
}

server {
    listen 443;
    ssl_certificate /etc/nginx/ssl/***.crt;
    ssl_certificate_key /etc/nginx/ssl/***;
    server_name _;
    return 404;
}

server {
    listen 80;
    server_name deploy.community.office;
    underscores_in_headers on;
    proxy_http_version 1.1;
    proxy_buffering off;

    rewrite ^(.*) https://$host$1 permanent;
}

server {
    listen 443 ssl;
    ssl_certificate /etc/nginx/ssl/***.crt;
    ssl_certificate_key /etc/nginx/ssl/***.key;
    underscores_in_headers on;
    proxy_buffering off;
    server_name deploy.community.office;
    client_max_body_size 0;
    proxy_connect_timeout       6000;
    proxy_send_timeout          6000;
    proxy_read_timeout          6000;
    send_timeout                6000;

    location ~ ^/bin/Main/(.*) {
        return 301 /Main/$1;
    }
    location ~ ^/bin/view/(.*) {
        return 301 /view/$1;
    }
    location ~ ^/bin/development/(.*) {
        return 301 /development/$1;
    }
    location ~ ^/bin/Blog/(.*) {
        return 301 /Blog/$1;
    }
    location ~ ^/bin/ReleaseNotes/(.*) {
        return 301 /ReleaseNotes/$1;
    }
    location ~ ^/bin/Favorites/(.*) {
        return 301 /Favorites/$1;
    }
    location ~ ^/bin/knowledgebase/(.*) {
        return 301 /knowledgebase/$1;
    }
    location ~ ^/bin/XWiki/(.*) {
        return 301 /XWiki/$1;
    }
    location ~ ^/bin/videos/(.*) {
        return 301 /videos/$1;
    }
    location ~ ^/bin/internal/(.*) {
        return 301 /internal/$1;
    }    
    location ~ ^/bin/categories/(.*) {
        return 301 /categories/$1;
    }

    # Handle requests to /main/ URLs and proxy them to /bin/main/ on backend
    location ~ ^/Main/(.*) {
        proxy_pass http://xwiki-experimental:8080/bin/Main/$1;
    }
    location ~ ^/view/(.*) {
        proxy_pass http://xwiki-experimental:8080/bin/view/$1;
    }
    location ~ ^/development/(.*) {
        proxy_pass http://xwiki-experimental:8080/bin/ReleaseNotes/$1;
    }
    location ~ ^/Blog/(.*) {
        proxy_pass http://xwiki-experimental:8080/bin/Blog/$1;
    }        
    location ~ ^/ReleaseNotes/(.*) {
        proxy_pass http://xwiki-experimental:8080/bin/ReleaseNotes/$1;
    }
    location ~ ^/Favorites/(.*) {
        proxy_pass http://xwiki-experimental:8080/bin/Favorites/$1;
    }
    location ~ ^/knowledgebase/(.*) {
        proxy_pass http://xwiki-experimental:8080/bin/knowledgebase/$1;
    }
    --
    location ~ ^/XWiki/(.*) {
        proxy_pass http://xwiki-experimental:8080/bin/XWiki/$1;
    }
    location ~ ^/videos/(.*) {
        proxy_pass http://xwiki-experimental:8080/bin/videos/$1;
    }
    location ~ ^/internal/(.*) {
        proxy_pass http://xwiki-experimental:8080/bin/internal/$1;
    }
    location ~ ^/categories/(.*) {
        proxy_pass http://xwiki-experimental:8080/bin/categories/$1;
    }

    location  / {
        proxy_pass_request_headers      on;
        proxy_pass http://xwiki-experimental:8080;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Scheme $scheme;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}