'local host refused to connect; this site can’t be reached

I’m a beginner and I’m using VS Code for coding. I’m learning HTML and CSS. When I debug the code on Chrome I see the following:

This site can’t be reached. localhost refused to connect.

Please, I need help to solve this problem, hope I get the help soon. Thank you!



Solution 1:[1]

Try Live Server Extension AND check for Firewall Settings

Solution 2:[2]

This problem is either because you didn't run anything to serve up the files or a firewall issue. If it's a firewall problem then check your firewall settings for anything that would block it, but most likely you need something to serve up your files. There are a number of ways you can serve the files

Option 1

Use the Live Server extension. In VS Code you can search for it and install it, then with a click of the "Go Live" button on the toolbar, it will serve your files on localhost and open the browser for you.

Option 2

Use http-server, which will serve up your files with a simple command line command.

Option 3

Use Node.JS to serve up your files. It's a very popular technology, but is more complicated compared to the first 2 options if you just want to fiddle with beginner JavaScript, you may need to add a start script.

-- OR -- just open the file with your web browser. You can double click on file you want to open from File Explorer or right-click >open with browser of your choice, in which case you don't need to run a background software to serve your files and you can use the browser UI and console for testing. In this case you just wouldn't have VS Code available to use with it's debugging tools.

Solution 3:[3]

Alternatively, you can try using Python's SimpleHTTPServer if you have Python on your system.

Solution 4:[4]

1- from xampp window select httpd.config and search about Listen make it Listen 80 , search about localhost make it ServerName localhost:80 2- from xampp window select httpd-ssl.config search about Listen make it Listen 443 , search about VirtualHost _default .. make it VirtualHost default:443 , i did that and localhost worked normally

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anshul
Solution 2 SendETHToThisAddress
Solution 3 ldtcoop
Solution 4 muhamad elalfy