设置本地主机并获取连接被拒绝的错误

Setting up a local host and getting a connection refused error

按照说明在 OS X 10.6.8 (SnowLeopard) 上使用本机 Apache 软件设置个人服务器,并按照说明修改 apache2.config 文件后,在浏览器中输入以下内容:

     http:// localhost 

(Chrome 或 Safari)returns 连接被拒绝错误。

要做什么?打开或关闭防火墙不会更改本地主机连接错误。

telnet returns 这个:

    Trying 127.0.0.1...
    telnet: connect to address 127.0.0.1: Connection refused
    Trying ::1...
    telnet: connect to address ::1: Connection refused
    Trying fe80::1...
    telnet: connect to address fe80::1: Connection refused
    telnet: Unable to connect to remote host  

返回的大量其他数据中的 netstat:

    udp4       0      0  localhost.64790        *.*   

在终端中输入 netstat -i returns:

    Name  Mtu   Network       Address            Ipkts Ierrs    Opkts Oerrs  Coll
    lo0   16384 <Link#1>                           954     0      954     0     0  
    lo0   16384 localhost   ::1                    954     -      954     -     -  
    lo0   16384 localhost   fe80:1::1              954     -      954     -     -  
    lo0   16384 127           localhost            954     -      954     -     -  

奇怪的是浏览器可以正常读取本地 HTML 和其他本地文件。例如输入:

file:///Library/Webserver/Documents/index.html.en  

returns "It works!"

但这并不能解决浏览器不响应本地主机的问题。

如有任何帮助,我们将不胜感激。

更新

所以我让 localhost 可以工作,但是当我将文件移动到正确的目录时链接断开了。
修复链接后,在 Safari 中键入 localhost 导致指南针飞出浏览器!

网络实用程序returns

Port Scanning host:  127.0.0.1
    Open TCP Port 80:    http

error_log 有这个警告:

Init: Session Cache is not configured [hint: SSlSessionCache]

ssl_module 包含在 LoadModule 部分。

在终端中输入 /usr/sbin/httpd 会出现以下错误:

(13)Permission denied: make_sock: could not bind to address 127.0.0.1:80  
no listening sockets available, shutting down
Unable to open logs

并且修改配置文件后监听8080电脑returns又报错:

(13)Permission denied: httpd: could not open error log file /private/var/log/apache2/error_log.  
Unable to open logs  

Julie Meloni 的手册指出:

This problem can arise if the user who built and installed  
Apache is different from the user trying to run it.

然而,在这种情况下情况并非如此。该手册没有提供有关如何解决此问题的说明。

使用ls -l /etc/apache2/httpd.conf终端检查权限后returns:

-rw-r--r-- 1 root wheel 18973 Dec 7 22:49 /etc/apache2/httpd.conf

据我所知,这表明该文件没有执行权限。在运行一个chmod 755之后计算机报告不允许该操作。

我打开了 Internet 共享首选项,所以这不是问题。

在终端中使用 curl http://127.0.0.1 returns 较短文件的 HTML 代码,但对于较长的文件,它仅 returns 有选择地 HTML 文件和一个奇怪的错误,它在屏幕上多次重复 MacBook 所有者的名字。

在终端中输入 tail /var/log/apache2/error_log returns:

[warn] Init: Session Cache is not configured [hint: SSLSessionCache]
Warning: DocumentRoot [/usr/docs/dummy-host.example.com] does not exist  
Warning: DocumentRoot [/usr/docs/dummy-host2.example.com] does not exist  
Warning: DocumentRoot [/usr/docs/dummy-host.example.com] does not exist  
Warning: DocumentRoot [/usr/docs/dummy-host2.example.com] does not exist 
[warn] NameVirtualHost *:80 has no VirtualHosts
[notice] Digest: generating secret for digest authentication ...
[notice] Digest: done
[notice] Apache/2.2.29 (Unix) PHP/5.4.45 DAV/2 mod_ssl/2.2.29 OpenSSL/0.9.8zg mod_perl/2.0.7 Perl/v5.16.2 configured -- resuming normal operations.

有人能给我指出正确的方向吗?

1.grep 使用 netstats 命令的进程确保 apache 正在使用端口 80(ipv4 和 ipv6) 2. 如果 lisner ip 设置为 127.0.0.1 或 0.0.0.0,请检查您的 apache conf 3.远程登录本地主机80 4. 试试其他浏览器firefox或safari

我花了很多时间试图理解网络实用程序的输出并试图找到要包含在 netscape|greps 中的变量终端。我仍然不确定是什么导致了错误。

我按照 BootPress 的 Kyle Gadds 在这个 youtube 视频中找到的说明进行操作:

https://www.youtube.com/watch?v=78wFR5Rp_Mw

我编辑了 apache 配置文件以包含:

 /User/[YOUR_USER_NAME]/Sites/www  

在文件中,我更改了 AllowOverrides 标志。 然后我注意到系统中缺少 Sites 文件夹,php.ini 文件是空的。
制作新的站点文件夹很容易。只需转到用户目录并让 Finder 创建一个名为 "Sites".
的新文件夹 但是替换 php 更加困难。我必须打开终端并输入

sudo cp /etc/php.ini.default /etc/php.ini 

在命令行中,这带回了 php.ini 文件,我不得不修改权限。然后它起作用了。我希望这可以帮助任何有类似问题的人。