如何配置vagrant以使用node.js

时间:2014-12-03 16:40:25

标签: node.js vagrant puphpet

运行带有vagrant的node.js时遇到问题 我有以下项目结构:

- public
    - hello.js
- vagrant
    - puphpet
    - Vagrantfile

这是我的puphpet配置:

---
vagrantfile-local:
    vm:
        box: puphpet/debian75-x64
        box_url: E:\vagrant boxes\debian-7.5-x86_64-v1.2-virtualbox.box
        hostname: ''
        memory: '1024'
        cpus: '1'
        chosen_provider: virtualbox
        network:
            private_network: 192.168.56.102
            forwarded_port:
                BD200PpFPN2U:
                    host: '3000'
                    guest: '3000'
        post_up_message: ''
        provider:
            virtualbox:
                modifyvm:
                    natdnshostresolver1: on
            vmware:
                numvcpus: 1
            parallels:
                cpus: 1
        provision:
            puppet:
                manifests_path: puphpet/puppet
                manifest_file: site.pp
                module_path: puphpet/puppet/modules
                options:
                    - '--verbose'
                    - '--hiera_config /vagrant/puphpet/puppet/hiera.yaml'
                    - '--parser future'
        synced_folder:
            uREBTumUq032:
                owner: www-data
                group: www-data
                source: ../
                target: /var/www
                sync_type: default
                rsync:
                    args:
                        - '--verbose'
                        - '--archive'
                        - '-z'
                    exclude:
                        - .vagrant/
                    auto: 'false'
        usable_port_range:
            start: 10200
            stop: 10500
    ssh:
        host: null
        port: null
        private_key_path: null
        username: vagrant
        guest_port: null
        keep_alive: true
        forward_agent: false
        forward_x11: false
        shell: 'bash -l'
    vagrant:
        host: detect
server:
    install: '1'
    packages: {  }
firewall:
    install: '1'
    rules: null
apache:
    install: '1'
    settings:
        user: www-data
        group: www-data
        default_vhost: true
        manage_user: false
        manage_group: false
        sendfile: 0
    modules:
        - rewrite
    vhosts:
        XWIOX0y1wPTF:
            servername: nodeapp.com
            docroot: /var/www/public
            port: '80'
            setenv:
                - 'APP_ENV dev'
            override:
                - All
            options:
                - Indexes
                - FollowSymLinks
                - MultiViews
            engine: php
            custom_fragment: ''
            ssl_cert: ''
            ssl_key: ''
            ssl_chain: ''
            ssl_certs_dir: ''
    mod_pagespeed: 0

这是hello.js文件

var http = require('http');

var server = http.createServer(function (request, response) {
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.end("Hello World!");
});
server.listen(3000);

我登录SSH然后我去var / www / public有文件hello.js。我跑

node hello.js

我没有收到任何错误/消息。

然后我去192.168.56.102:3000然后我得到:
连接已超时

地址192.168.56.102返回404状态代码,因此apache正在运行。

我尝试将config.yaml中的host和guest更改为端口8080,但它没有用。

我做错了吗?

1 个答案:

答案 0 :(得分:3)

尝试将转发的端口删除到3000并将其添加到防火墙部分。