我想运行一个非常简单的HTTP服务器.每个GET请求都example.com应该index.html提供给它,但作为常规HTML页面(即,与您阅读普通网页时相同的体验).
使用下面的代码,我可以阅读的内容index.html.我如何index.html作为常规网页?
var http = require('http');
var fs = require('fs');
var index = fs.readFileSync('index.html');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(index);
}).listen(9615);
Run Code Online (Sandbox Code Playgroud)
下面的一个建议很复杂,需要我为get我想要使用的每个资源(CSS,JavaScript,图像)文件写一行.
如何使用一些图像,CSS和JavaScript提供单个HTML页面?
如何配置Spring Boot应用程序侦听的TCP/IP端口,因此它不使用默认端口8080.
由于这篇文章多年来引起了很多关注,我在本文的最后列出了每个平台的顶级解决方案.
原帖:
我希望我的node.js服务器在后台运行,即:当我关闭终端时,我希望我的服务器继续运行.我已经用Google搜索了这个教程,但它没有按预期工作.因此,我没有使用该守护进程脚本,而是认为我只使用了输出重定向(2>&1 >> file部分),但这也没有退出 - 我的终端中出现一个空行,就像是在等待输出/错误.
我也尝试将该过程放在后台,但是一旦我关闭终端,该过程也会被杀死.
那么当我关闭本地计算机时,如何让它保持运行?
最佳方案:
尝试通过浏览器访问localhost时出现此错误.
AH01630: client denied by server configuration
Run Code Online (Sandbox Code Playgroud)
我使用以下方法检查了我的站点文件
sudo chmod 777 -R *
Run Code Online (Sandbox Code Playgroud)
这是我的配置文件:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/user-name/www/myproject
<Directory />
Options FollowSymLinks
AllowOverride all
Allow from all
</Directory>
<Location />
Allow from all
Order Deny,Allow
</Location>
<Directory /home/user-name/www/myproject/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride all
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, …Run Code Online (Sandbox Code Playgroud) 这可能是一个非常基本的问题,但我根本就没有得到它.使用Express.js创建应用程序和启动应用程序侦听端口1234 之间的区别是什么,例如:
var express = require('express');
var app = express();
//app.configure, app.use etc
app.listen(1234);
Run Code Online (Sandbox Code Playgroud)
并添加一个http服务器:
var express = require('express');
var http = require('http');
var app = express();
var server = http.createServer(app);
//app.configure, app.use etc
server.listen(1234);
Run Code Online (Sandbox Code Playgroud)
有什么不同?
如果我导航到http://localhost:1234,那么我得到相同的输出.
在Debian服务器上,我安装了Node.js. 我了解如何使用此命令行从putty启动应用程序:
node /srv/www/MyUserAccount/server/server.js
Run Code Online (Sandbox Code Playgroud)
并在地址50.51.52.53:8080(IP和端口)上找到它.
但是一旦我关闭腻子,我就再也无法到达地址50.51.52.53:8080了.
如何使Node.js应用程序永久运行?
你可以猜到,我是Linux和Node.js的初学者.
我正在尝试构建一个PHP站点,我想测试我的PHP文件而不将它们上传到我的主机.在我上传它们之前,基本上在我自己的机器上测试它们.我怎么做?
为什么我会收到此错误?
shibly@mybox:~/blog$ rails server
/home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError)
from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require'
from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler.rb:99:in `require'
from /home/shibly/blog/config/application.rb:7:in `<top (required)>'
from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:78:in `require'
from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:78:in `block in server'
from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `server'
from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:9:in `require'
from bin/rails:9:in `<main>
Run Code Online (Sandbox Code Playgroud) 安装Windows 10后,我不断收到" 无法找到服务器DNS地址 "错误.
我将能够使用互联网4-5分钟,之后20-25分钟我将得到上述错误.
我该如何解决这个问题?
我在Windows 7上成功安装了XAMPP(xampp-win32-1.8.2-0-VC9-installer.exe).但不幸的是,从XAMPP控制面板运行Apache时发现以下错误:
5:38:38 PM [Apache] Error: Apache shutdown unexpectedly.
5:38:38 PM [Apache] This may be due to a blocked port, missing dependencies,
5:38:38 PM [Apache] improper privileges, a crash, or a shutdown by another method.
5:38:38 PM [Apache] Press the Logs button to view error logs and check
5:38:38 PM [Apache] the Windows Event Viewer for more clues
5:38:38 PM [Apache] If you need more help, copy and post this
5:38:38 PM [Apache] entire log window on the forums
Run Code Online (Sandbox Code Playgroud)
