[英]Node js connecting to port in Wamp
我試圖在Node.js中創建自己的“服務器”並將其連接到WAMP端口8888。但是不知何故我什么也回不來,不是localhost:8888頁面上的響應,甚至不是console.log?
當我使用其他端口時,什至沒有任何反應...
var http = require('http');
function onRequest(request, response){
console.log("A user made a request" + request.url);
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Here is some data");
response.end();
}
http.createServer(onRequest).listen(8888);
console.log("Server is now running...");
有人可以以正確的方式幫助我嗎?
格蕾茲·詹斯(Greetz Jens)
我認為,您需要在WAMP服務器的文檔根文件夾中使用此.htaccess文件:
# .htaccess file in document root.
Options +FollowSymLinks -Indexes -MultiViews
<IfModule mod_rewrite.c>
RewriteRule ^(.+) http://localhost:8888/$1 [P]
</IfModule>
現在,任何HTTP請求(例如http://localhost/any/path/you/want
都將重定向到端口8888
。
當然,您的Apache應該在與8888
不同的端口上監聽,您可以保留默認的80
端口。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.