当我尝试通过 `http://localhost/xampp/htdocs/index.html` 打开一个 HTML 文件时,它说无法连接到 localhost
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15055171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
when I try to open an HTML file through `http://localhost/xampp/htdocs/index.html` it says unable to connect to localhost
提问by user1841718
I have installed XAMPP , there is a htdocs
folder and inside it index.html
file ,
when I try to open it in my browser through http://localhost/xampp/htdocs/index.html
it says
unable to connect to localhost .
我已经安装了 XAMPP,有一个htdocs
文件夹,里面 有一个 index.html
文件,当我尝试在我的浏览器中打开它时,http://localhost/xampp/htdocs/index.html
它说无法连接到 localhost。
what is wrong ?
怎么了 ?
回答by Shema_Thomas
instead of
代替
http://localhost/xampp/htdocs/index.html
try just
试试吧
http://localhost/index.html
or if index.html is saved in a folder in htdocs then
或者如果 index.html 保存在 htdocs 的文件夹中,则
http://localhost/<folder-name>/index.html
回答by Fr0g
htdocs
is your default document-root directory, so you have to use localhost/index.html
to see that html file. In other words, localhost
is mapped to xampp/htdocs
, so index.html
is at localhost
itself. You can change the location of document root by modifying httpd.conf
and restarting the server.
htdocs
是您的默认文档根目录,因此您必须使用它localhost/index.html
来查看该 html 文件。换句话说,localhost
被映射到xampp/htdocs
,所以index.html
是localhost
自己。您可以通过修改httpd.conf
和重新启动服务器来更改文档根目录的位置。
回答by ComFreek
Start your XAMPP server by using:
使用以下命令启动 XAMPP 服务器:
{XAMPP}\xampp-control.exe
{XAMPP}\apache_start.bat
{XAMPP}\xampp-control.exe
{XAMPP}\apache_start.bat
Then you have to use the URI http://localhost/index.html
because htdocs
is the document root of the Apache server.
然后您必须使用 URI,http://localhost/index.html
因为htdocs
是 Apache 服务器的文档根。
If you're getting redirected to http://localhost/xampp/*
, then index.php
located in the htdocs
folder is the problem because index.phpfiles have a higher priority than index.htmlfiles.
You could temporarily rename index.php.
如果您被重定向到http://localhost/xampp/*
,则index.php
位于htdocs
文件夹中是问题所在,因为index.php文件的优先级高于index.html文件。您可以暂时重命名index.php。
回答by Nickolaus
You need to start your Apache Server normally you should have an xampp icon in the info-section from the taskbar, with this tool you can start the apache server as wel as the mysql database (if you need it)
您需要正常启动 Apache 服务器,您应该在任务栏的信息部分中有一个 xampp 图标,使用此工具您可以启动 apache 服务器以及 mysql 数据库(如果需要)
回答by Nesimi Taghizade
All created by user files saved in C:\xampp\htdocs
directory by default,
so no need to type the default path in a browser window, just type
http://localhost/yourfilename.php
or http://localhost/yourfoldername/yourfilename.php
this will show you the content of your new page.
C:\xampp\htdocs
默认情况下,所有由保存在目录中的用户文件创建,因此无需在浏览器窗口中键入默认路径,只需键入
http://localhost/yourfilename.php
或http://localhost/yourfoldername/yourfilename.php
这将显示新页面的内容。
回答by David
I just put an index.html file in /htdocs and type in http://127.0.0.1/index.html- and up comes the html.
我只是在 /htdocs 中放了一个 index.html 文件,然后输入http://127.0.0.1/index.html- 然后就是 html。
Add a folder "named Forum" and type in 127.0.0.1/forum/???.???
添加一个文件夹“命名论坛”并输入 127.0.0.1/forum/???.???
回答by Anne
You should simply create your own folder in htdocs and save your .html and .php files in it. An example is create a folder called myNewFolder directly in htdocs. Don't put it in index.html. Then save all your.html and .php files in it like this-> "localhost/myNewFolder/myFilename.html" or "localhost/myNewFolder/myFilename.php" I hope this helps.
您应该简单地在 htdocs 中创建您自己的文件夹并将您的 .html 和 .php 文件保存在其中。一个例子是直接在 htdocs 中创建一个名为 myNewFolder 的文件夹。不要把它放在 index.html 中。然后像这样保存所有 your.html 和 .php 文件->“localhost/myNewFolder/myFilename.html”或“localhost/myNewFolder/myFilename.php”我希望这会有所帮助。