Bha*_*ani 5 hosting node.js server
任何人都想知道如何在Godaddy上安装节点服务器的站点或参考.
neb*_*ulr 10
是的,这是可能的.不知怎的,我从来没有见过任何人真正正确回答这个问题.这适用于最基本的共享主机方案.我已经成功地设置了几种不同的方式.我认为第二个可能是你想要的:
1. cgi-node http://www.cgi-node.org/home
基本上这取代了灯堆上的PHP.您可以像运行PHP一样通过节点运行javascript.它具有节点js的所有相同功能,但仅适用于模板渲染.
<html>
<body>
<?
var helloWorld = 'Hello World!';
write(helloWorld + '<br/>');
?>
<?= helloWorld ?>
<br/>
<b>I can count to 10: </b>
<?
for (var index= 0; index <= 10; index++) write(index + ' ');
?>
<br/>
<b>Or even this: </b>
<?
for (var index= 0; index <= 10; index++) {
?>
<?= index ?>
<? } ?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
要么
2.独立服务器(这适用于NameCheap主机和GoDaddy共享主机)
在您的共享主机帐户中,您需要SSH才能执行此操作.因此,您可能需要从其客户支持升级或请求SSH访问.下载最新的NodeJS https://nodejs.org/en/download/.共享主机可能在linux 64位.您可以通过运行以下命令在linux或unix上进行检查:
uname -a
Run Code Online (Sandbox Code Playgroud)
下载Linux二进制文件并在/ home/username/bin /中下载bin/node(以及bin/npm文件,如果你想在服务器上使用npm)文件(如果它不存在则创建bin文件夹) )在服务器上.将权限755放在节点二进制文件上.所以你应该在这里有一个新文件:
/home/username/bin/node
打开/ home/username/public_html中的.htaccess文件并添加以下行:
RewriteEngine on
RewriteRule (.*) http://localhost:3000/$1 [P,L]
Run Code Online (Sandbox Code Playgroud)
在/ home/username/public_html中创建一个文件,然后将其命名为app.js. 在该文件中添加以下行:
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('NodeJS server running on Shared Hosting\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Run Code Online (Sandbox Code Playgroud)
SSH进入服务器运行以下命令:
cd /home/username/public_html
which node # this should return ~/bin/node
node app.js & # This will create a background process with the server running
Run Code Online (Sandbox Code Playgroud)
如果你可以正确设置这个设置,从长远来看,这将为你节省大量资金,而不是使用AWS或Heroku等.
小智 6
我通过以下方式在具有多个域的 godaddy 共享主机上安装了节点:
通过 SSH 连接到 godaddy 服务器
在主文件夹中安装 nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
Run Code Online (Sandbox Code Playgroud)nvm install 10.14.0
(或首选节点版本)注意:如果执行时出现 nvm command not found $nvm --version,只需关闭并重新启动 SSH 终端
在要运行节点应用程序的站点的文件夹中,添加.httaccess文件
~/public_html/site folder/.htaccess
Run Code Online (Sandbox Code Playgroud)
重写引擎开启
RewriteRule (.*) http://localhost:3000/$1 [P,L]
Run Code Online (Sandbox Code Playgroud)注意:.htaccess可用于定位单个文件夹,更改立即生效,无需重新启动服务器。
按照 @nebulr 的指示在站点文件夹中运行 app.js 或节点服务器
$node app.js &
Run Code Online (Sandbox Code Playgroud)Yes, this is possible on even the cheapest shared hosting tier. @nebulr instructions are correct. Here is a slightly updated and expanded version for noobs like me.
(1) Enable SSH on your shared hosting account:
• Log into your GoDaddy hosting and turn on SSH Access (on the Dashboard, it's in "Settings" on the bottom right). Take note of the cPanel login username and change the password if you don't remember it. Note that you also may need to create keys in CPanel, under "Security" and "SSH Access".
(2) Install the nodejs program itself:
• Download the Node.js binaries from https://nodejs.org/en/download/ Specifically you'll want the Linux x64 version (direct link https://nodejs.org/dist/v10.15.0/node-v10.15.0-linux-x64.tar.xz)
• Unpack this .tar file on your computer and look inside for the bin folder (on a Mac you may need a program such as The Unarchiver to unpack it). The bin folder will have a file called "node" that's about 40Mb. This "node" file is the only thing we're going to use in this package.
• Using the CPanel File Manager or FTP program, create a folder on the server called "bin" in /home/yourUserName/ and give it permissions of 755. Note this is NOT inside public_html.
• Upload the "node" file to /home/yourusername/bin/
(3) Create a simple nodejs script:
• Open a text editor (like Sublime) and create a new file called "app.js" (or whatever):
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('NodeJS server running on Shared Hosting\n');
});
server.listen(port, hostname, () => {
console.log('Server running at http://${hostname}:${port}/');
});
Run Code Online (Sandbox Code Playgroud)
Note that this is just the basic server app from https://nodejs.org/en/docs/guides/getting-started-guide/
• Open your CPanel File Manager or FTP program, and upload the app.js file to /home/yourusername/public_html/
(4) Modify the .htaccess file:
• Use your FTP program to add these lines to the .htaccess file:
RewriteEngine on
RewriteRule (.*) http://localhost:3000/$1 [P,L]
Run Code Online (Sandbox Code Playgroud)
Note that the .htaccess file is probably blank by default. Also note that you can use nano, vim, or emacs in SSH to edit the .htaccess file if you're brave or 1337.
(5) Start the node server:
• SSH into the godaddy server by opening Putty (Windows) or Terminal (Mac) and at the command line type: ssh username@website.com (where username is your hosting account's cPanel login)
The server should respond with username@website.com's password: which is where you enter the cPanel login password.
Note: If it's your first time SSH'ing to the server, you'll get a message: The authenticity of host 'X.X.X.X' can't be established. RSA key fingerprint is XXXX. Are you sure you want to continue connecting (yes/no)? Type yes and continue on.
• Navigate to /home/yourUserName/public_html/ by typing cd public_html. Start the node server script by typing: node app.js &
In a couple seconds you should see the message: Server running at http://127.0.0.1:3000/
(6) Check it out:
• Open a web browser and type your website's URL. You should get a white page with the text NodeJS server running on Shared Hosting or whatever message you put in line 9 of app.js above. Note that you can't use the IP address on a shared hosting account, you need to use the domain name.
您有两种选择来托管节点应用程序。- 从 godaddy 或 digitalocean 等购买自己的 VPS 服务器。 - Godaddy 本身提供运行其节点实例的选项。请参考https://in.godaddy.com/pro/one-click-installation/node-js
| 归档时间: |
|
| 查看次数: |
8692 次 |
| 最近记录: |