简体   繁体   English

如何配置vagrant与node.js一起使用

[英]How to configure vagrant to work with node.js

I have problem with running node.js with vagrant. 我在使用流浪汉运行node.js时遇到问题。
I have following structure of project: 我有以下项目结构:

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

Here's my puphpet config: 这是我的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

Here is hello.js file 这是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);

I log to SSH then I go to var/www/public there is file hello.js. 我登录到SSH,然后转到var / www / public,其中有文件hello.js。 I run 我跑

node hello.js

I dont get any error/message. 我没有收到任何错误/消息。

Then I go to 192.168.56.102:3000 and after while I get: 然后我转到192.168.56.102:3000,然后我得到:
The connection has timed out 连接已超时

Address 192.168.56.102 returns 404 status code, so apache is working. 地址192.168.56.102返回404状态代码,因此apache正在运行。

I tried change host and guest in config.yaml to port 8080 but it didnt work. 我尝试将config.yaml中的主机和来宾更改为端口8080,但没有成功。

Did I do something wrong? 我做错什么了吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM