server {
	listen 80;
	listen [::]:80;

	set $root /var/www/site.local/site/backend;
	root $root;

	index index.php index.html index.htm;

	server_name site.local;

	set $php_sock unix:/run/php/php8.3-fpm.sock;

	location / {
		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-Forwarded-Proto $scheme;
		proxy_read_timeout 1m;
		proxy_connect_timeout 1m;
		proxy_pass http://localhost:3000;
    	}

    	location /__admin/ {
		index index.php;
	      	try_files $uri $uri/ @bitrix;
    	}

	  location /upload/ {
            try_files $uri @bitrix;
		fastcgi_pass $php_sock;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        	include fastcgi_params;
        }


	location /api/ {
		index index.php;
		add_header Access-Control-Allow-Origin *;
	      	try_files $uri $uri/ @bitrix;
	}

    	location ~* /upload/.*\.(php|php3|php4|php5|php6|phtml|pl|asp|aspx|cgi|dll|exe|shtm|shtml|fcg|fcgi|fpl|asmx|pht|py|psp|rb|var)$ {
                types {
                        text/plain text/plain php php3 php4 php5 php6 phtml pl asp aspx cgi dll exe ico shtm shtml fcg fcgi fpl asmx pht py psp rb var;
                }
        }

        location ~* ^/bitrix/(modules|local_cache|stack_cache|managed_cache|php_interface) {
		deny all;
	}

	location /bitrix/ {
		index index.php;
		try_files       $uri $uri/ @bitrixadm;
	}

	location ~ \.php$ {
		try_files $uri @bitrix;
		fastcgi_pass $php_sock;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        	include fastcgi_params;
	}

	location @bitrix {
		fastcgi_pass    $php_sock;
		include fastcgi_params;
		fastcgi_param SCRIPT_FILENAME $document_root/bitrix/urlrewrite.php;
	}

	location ~* /\.(svn|hg|git) {
		deny all;
	}
}
