2011-01-07 26 views
1

我最近在名爲「test」的Mac OS上本地創建了一個新的Ruby on Rails 3應用程序。在localhost(Apache,Passenger和VirtualHosts)上發佈新的Ruby on Rails 3應用程序的奇怪問題

由於我使用的Apache2,在私人的/ etc/apache2的/ httpd.conf中我設置了虛擬主機的 「測試」 應用:

<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.使用 '網絡Uility'

我做了結果如下:

ping: cannot resolve test.pjtmain.localhost: Unknown host 

,我做了一個查找與follonwing結果:

; <<>> 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.在/私營/ 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客運

4.由於我沒有什麼不更改爲新的 「測試」 應用程序,我期望看到默認的RoR index.html頁面:

alt text

5.看來,在 '控制檯消息' 有 'dscacheutil -flushcache' 任何警告或錯誤

6.運行後, '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 
+1

你可以看看Apache日誌,看看它是否甚至獲取請求? – hornairs 2011-01-07 00:41:45

+0

在/ private/var/log/apache2中:'ssl_request_log'文件爲空; 'error_log'和'access_log'文件報告與'test.pjtmain.localhost'無關的舊值。 – user502052 2011-01-07 00:58:06

回答

3

這沒有按」 t看起來像是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,您即將關閉並正在運行。