我最近在Mac OS上本地创建了一个新的Ruby on Rails 3应用程序,名为“test”。
由于我使用apache2,在私有/ etc / apache2 / httpd.conf 中我为“test”应用程序设置了VirtualHost:
<VirtualHost *:443>
ServerName test.pjtmain.localhost:443
DocumentRoot "/Users/<my_user_name>/Sites/test/public"
RackEnv development
<Directory "/Users/<my_user_name>/Sites/test/public">
Order allow,deny
Allow from all
</Directory>
# SSL Configuration
SSLEngine on
...
</VirtualHost>
<VirtualHost *:80>
ServerName test.pjtmain.localhost
DocumentRoot "/Users/<my_user_name>/Sites/test/public"
RackEnv development
<Directory "/Users/<my_user_name>/Sites/test/public">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
当然我重新启动apache2,但尝试访问http://test.pjtmain.localhost/
我收到以下错误消息:
FIREFOX
Oops! Firefox could not find test.pjtmain.localhost
Suggestions:
*
Search on Google:
...
SAFARI
Safari can’t find the server.
Safari can’t open the page “http://test.pjtmain.localhost/” because Safari can’t find the server “test.pjtmain.localhost”.
我在httpd.conf文件中设置了如上所述的其他RoR3应用程序,但它们都可以正常工作。
问题是什么(也许与apache无关......)
备注:
1.
使用'网络无效'
我做了一个 Ping ,结果如下:
ping: cannot resolve test.pjtmain.localhost: Unknown host
我做了一个 Lookup ,结果如下:
; <<>> DiG 9.6.0-APPLE-P2 <<>> test.pjtmain.localhost +multiline +nocomments +nocmd +noquestion +nostats +search
;; global options: +cmd
<MY_ISP_NAME>.com. 115 IN SOA dns1.<MY_ISP_NAME>.com. dnsmaster.<MY_ISP_NAME>.com. (
2010110500 ; serial
10800 ; refresh (3 hours)
900 ; retry (15 minutes)
604800 ; expire (1 week)
86400 ; minimum (1 day)
)
2.
在/ private / etc / hosts我有这段代码:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
3.
我正在使用Phusion Passenger
4.
由于我没有对新的“测试”应用程序进行任何改动,我希望看到默认的RoR index.html页面:
5.
似乎在“控制台消息”中有任何警告或错误
6.
运行'dscacheutil -flushcache'后,'dscacheutil -statistics'响应为:
Overall Statistics:
Average Call Time - 0.000304
Cache Hits - 5311
Cache Misses - 6113
Total External Calls - 5654
Statistics by procedure:
Procedure Cache Hits Cache Misses External Calls
------------------ ---------- ------------ --------------
getpwnam 1496 149 1645
getpwuid 749 11 760
getgrnam 157 28 185
getgrgid 76 7 83
getservbyname 2818 15 26
getservbyport 0 3 3
getprotobyname 1 1 2
getfsent 0 0 2
gethostbyname 14 2816 13
gethostbyaddr 0 116 116
gethostbyname_service 0 0 2817
_flushcache 0 0 2
答案 0 :(得分:3)
这似乎根本不是Apache问题。问题在于您使用DNS。
localhost
是机器用于与自身对话的连接的占位符。它不是您可以添加其他名称的域的根(即test.pjtmain.
部分)。
您的Mac可能有一个名称,您可以在“首选项”实用程序的“共享”部分找到该名称。我们说它是yourmachine
。共享面板将指示您可以yourmachine.local
。
假设您想为测试应用提供唯一的域名,请尝试为您的测试域添加新行/private/etc/hosts
:
127.0.0.1 pjtmain.yourmachine.local
与yourmachine.local
不同,这不会自动从网络上的其他计算机上运行,但它可以用于本地测试。
尽管如此,您可能需要考虑在开发期间通过在开发站点时直接运行开发服务器来避免整个问题。打开终端窗口,cd到Rails应用程序的根目录,然后运行rails server
(如果它是Rails 3应用程序)或script/server
(Rails 2)。浏览到http://localhost:3000
即可关闭并运行。