Re: [問題] 一個IP或一台電腦架不同網站?

看板Linux作者 (呆呆小狼)時間13年前 (2011/04/14 03:17), 編輯推噓2(2010)
留言12則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《ringballer (.)》之銘言: : 我想用一個IP或一個電腦架兩個網站 網站名稱分別是host1跟host2 : 一般apache是把/var/www/html/index.html 當作首頁 : 假設我的IP是 123.123.123.123 : 當瀏覽器連接到 http://123.123.123.123/ 就等同連線到 index.html : 看httpd.conf檔的感覺 好像只能設定一個首頁index.html : 而且 http://host1 http://host2 : 都只能對應到 http://123.123.123.123:80/index.thml : 目前想到一個IP 開不同網站的方法就是開不同的port : 假設我開81跟82好了 再去申請兩個host name:host1跟host2 : 讓 http://host1對應到 http://123.123.123.123:81/index1.html : 讓 http://host2對應到 http://123.123.123.123:82/index2.html : 可以這樣嗎?要怎麼弄? : 滿困惑的 ....謝謝大家 : -- : ※ 發信站: 批踢踢實業坊(ptt.cc) : ※ 編輯: ringballer 來自: 118.168.120.121 (04/13 13:42) : 推 WolfLord:Keyword <VirtualHost> 04/13 13:47 : → ringballer:謝謝 04/13 13:50 : 推 asimon:不需要開不同port.. 04/13 14:52 : → ringballer:目前查到VirtualHost的方式,是在dns前面加名字,比如說 04/13 15:03 : → ringballer:www.yahoo.com跟www1.yahoo.com.可是我如果想要一個是 04/13 15:04 : → ringballer:host1.org另外一個是host2.com呢? 04/13 15:05 : → ringballer:我好像又找到了,我先研究研究. 04/13 15:08 : ※ 編輯: ringballer 來自: 118.168.70.109 (04/13 15:10) : 推 kylekai:你需要的是 Name-based Virtual Host .... 04/13 15:17 : → yanli2:你需要的是 apache 裡面的 http.conf 裡面的virtual host 04/13 16:41 : → yanli2:或是看看 apache/conf/extra/httpd-vhosts.conf 04/13 16:42 : → ringballer:可以了.謝謝大家 04/13 17:07 : 我在httpd.conf加的東西 : NameVirtualHost *:80 httpd.conf: # Default Server <VirtualHost *:80> DocumentRoot /var/www/html <Directory "/var/www/html"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost> #Host1 <VirtualHost host1.domain1.com:80> DocumentRoot /home/vhost1/html ServerName host1.domain1.com </VirtualHost> #Host2 <VirtualHost host2.domain1.com:80> DocumentRoot /home/vhost2/html ServerName host2.domain1.com </VirtualHost> #Host3 <VirtualHost host1.domain2.com:80> DocumentRoot /home/vhost3/html ServerName host1.domain2.com </VirtualHost> #Host4 <VirtualHost host2.domain2.com:80> DocumentRoot /home/vhost3/html ServerName host2.domain2.com </VirtualHost> #Host5 <VirtualHost host3.domain1.com:80> DocumentRoot /home/vhost4/html ServerName host3.domain1.com </VirtualHost> ::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::::: /etc/hosts: xxx.xxx.xxx.xxx host1.domain1.com host2.domain1.com host3.domain1.com\ host1.domain2.com host2.domain2.com.....> #### 修改HOSTS的目的在預防PUBLIC DNS失效倒制的APACHE無法成功起用。 每個VHOST除非有特殊設定,不然只要打入必要資訊就可以了。 -- 作別人不願作的事,是好人!。 作別人不敢作的事,是壞人!。 作別人不能作的事,是天才!。 作別人不會作的事,是…腦殘!! WolfLord -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.46.207.75

04/14 05:17, , 1F
我試了一下 /etc/hosts 沒有設定也可以用. 我設定之後
04/14 05:17, 1F

04/14 05:18, , 2F
反而會怪怪的.不同網頁會抓到不同資料夾.理論上應該不
04/14 05:18, 2F

04/14 05:20, , 3F
可能.所以我覺得怪.PS:我用的是浮動IP.IP我用`ifconfig
04/14 05:20, 3F

04/14 05:21, , 4F
ppp0 | grep 'inet addr:' | cut -d: -f2 | awk
04/14 05:21, 4F

04/14 05:23, , 5F
'{ print $1}'`來表示.
04/14 05:23, 5F

04/14 05:27, , 6F
我發現問題在哪裡了:default host我用virtual host的方
04/14 05:27, 6F

04/14 05:28, , 7F
式去設定,/etc/hosts也同時註解的型況下,會出問題.
04/14 05:28, 7F

04/14 05:30, , 8F
我上篇的設定方式,是把httpd.conf都用*:80設定,熊熊在
04/14 05:30, 8F

04/14 05:32, , 9F
/etc/hosts加入註解.這樣也會抓錯網頁.
04/14 05:32, 9F

04/14 05:37, , 10F
還是說這是我一開始沒設NameVirtualHost *:80的關係
04/14 05:37, 10F

04/14 13:28, , 11F
你用浮動IP就沒辦法用HOSTS內定的方式,用NameVirtualHost
04/14 13:28, 11F

04/14 13:29, , 12F
先宣告一次吧
04/14 13:29, 12F
文章代碼(AID): #1DfVRASv (Linux)
文章代碼(AID): #1DfVRASv (Linux)