2014-02-22 71 views
0

我設法登錄到Ubuntu並做一些安裝和FTP一些圖像文件(只是爲了測試網絡是否工作)。我如何使用瀏覽器中的公共IP或彈性IP來查看它?我不想傳輸DNS,因爲我現在正在測試Node.js。AWS EC2 ipaddress

+0

你想用Node.js提供文件,或者你想以靜態方式查看它們('http:// dns-to-my-server/some_image.jpg')? –

+0

@Uri Agassi是的,我想像你說的那樣以靜態的方式查看它們,以完成整個學習圈。 – sooon

回答

1

在EC2上啓動ubuntu實例不會自動將其作爲服務器。您需要真正運行Web服務器才能在瀏覽器中查看該計算機上的文件。

對於靜態文件,您可以使用簡單的網絡服務器,如python's SimpleHTTPServerwebfsd

如果您計劃使用Node.js的工作,你可能更喜歡在node.js中寫一個小Hello World代替:

// Load the http module to create an http server. 
var http = require('http'); 

// Configure our HTTP server to respond with Hello World to all requests. 
var server = http.createServer(function (request, response) { 
    response.writeHead(200, {"Content-Type": "text/plain"}); 
    response.end("Hello World\n"); 
}); 

// Listen on port 8000, IP defaults to 127.0.0.1 
server.listen(8000); 

// Put a friendly message on the terminal 
console.log("Server running at http://127.0.0.1:8000/"); 
+0

這對我的工作感謝,但我終於決定從頭開始[本教程],只是爲了看看(本教程)(http://techprd.com/setup-node-js-web-server-on-amazon-ec2/)如果我錯過任何重要的東西。 – sooon

0

您需要允許您在EC2實例正在使用的安全組上運行node.js的端口。然後你就可以在http://<public ip of your server>:<port where node.js is running on>

Node.js port

+0

是的,我已經做到了。我可以連接CLI和SFTP。但我不確定如何使它適用於瀏覽器。還有什麼我可以檢查的? – sooon

1

訪問您的網站,我猜這是與服務器的NodeJS定義

的例子

服務器提供的默認server.listen做.listen(1337,「127.0.0.1」);

NodeJS只會監聽來自127.0.0.1的連接。

得到它的迴應所有請求,嘗試setupthe主機部分是可選的)

server.listen(1337)以下;

+0

對不起,我對服務器端來說比較新。你介意給我一些示例代碼嗎? – sooon

+1

'var http = require('http'); res.writeHead(200,{'Content-Type':'text/plain'}); res.end('Hello World \ n'); }(函數(req,res) ).listen(8080,「0.0.0.0」); console.log('Server running at http://0.0.0.0:8080/');' 用你自己的代碼替換8080。重要的部分是.listen(port,IP);如果你沒有指定它,它只會聽本地主機(127.0.0.1) – StuartB

+0

對不起,這個新手問題,但我在哪裏做你提供的代碼?在節點納米? – sooon

0
  1. EC2實例是不是默認的Web服務器。

    命令和apt-get安裝的httpd

應該做的伎倆。 然後,您將需要啓動服務器:

sudo service httpd start 

然後我會用命令在以下位置創建的index.html測試工作。

sudo vim /var/www/html index.html 
  • 默認安全組設置不允許入站流量。如果使用以下方式訪問AWS EC2控制檯: AWS EC2 Instance Console 並編輯安全組。允許所有IP使用HTTP。

  • 現在,如果您轉到{https:// YOUR-PUBLIC-IP-ADDRESS /},它應顯示index.html的html內容。 可以在類似的筆記上添加圖像。