Make sure the URL in config.php matches with the URL you use to access the website.
You shouldn't access the website using the /public subfolder. If you are not accessing it with the public subfolder but still see the same error, it means you have a proxy redirect rule somewhere in your hosting that tries to redirect to public instead of serving from public.