我在我的linux本地主机上testing这个。
这就是我想要的:
balter@spectre:/var/www/html$ cat .htaccess Action cgi-node "/usr/bin/env node" AddHandler cgi-node .js balter@spectre:/var/www/html$ ls -al hello.js -rwxr-xr-x 1 balter balter 99 Oct 31 13:17 hello.js balter@spectre:/var/www/html$ cat hello.js #!/usr/bin/env node console.log("Content-Type: text/html"); console.log("hello from javascript"); balter@spectre:/var/www/html$ node hello.js Content-Type: text/html hello from javascript
当我访问localhost/hello.js所有我看到的是hello.js的内容
另外我想知道我是否真的打开了cgi。 我想我做了,因为PHP的工作。 但是我没有启用cgi模块,或者在apache.conf打开。
所以我添加了cgi.load并添加到我的apache.conf
################################################################### ######### Adding capaility to run CGI-scripts ################# ServerName localhost ScriptAlias /cgi-bin/ /var/www/cgi-bin/ Options +ExecCGI AddHandler cgi-script .cgi .pl .py .js
现在,我明白了
被禁止
您无权访问此服务器上的/hello.js。 本地端口80上的Apache / 2.4.18(Ubuntu)服务器
顺便说一句,与相同的hello.py相同。