Please run EtreCheck and post the report here. This is a diagnostic test.
https://etrecheck.com
Click “Free Download” button, open Downloads folder, click on it to open, and then select ”Open”.
Click on the bouncing EtreCheck icon in the Dock.
“Choose a problem” from the popup menu box, and then “Start EtreCheck” in the dialog.
Click “Share Report” button in the toolbar, select “Copy to Clipboard” .
Paste it into the reply.
Safari cannot connect to server.
Go step by step and test.
1. Restart the router.
2. Deselect Proxies, if selected.
System Preference > Network > Advanced > Proxies Tab
Unlock the lock if you have to.
Under "Select a protocol…”, uncheck any box if check-marked.
Click "OK” then "Apply”.
https://support.apple.com/guide/safari/if-you-cant-open-a-website-ibrw1071/mac
3. Uninstall any Profile you have not installed knowingly.
Section: Remove a configuration profile from your Mac
Profiles: https://support.apple.com/guide/mac-help/configuration-profiles-standardize-settings-mh35561/mac
3. Disable/uninstall any anti-virus software or web monitoring software if installed.
4. If you cannot still connect to internet:
Startup in Safe Mode. https://support.apple.com/lv-lv/HT20126
Login to your account. Launch Safari and test.
Click in the menu bar and choose “Restart”