Как настроить / etc / hosts в vagrant guest

0

Задний план:

  1. Я запускаю узел ubuntu, затем я использовал puphpet для создания ubuntu гостя с PHP и Nginx
  2. У гостя, /etc/hosts у меня есть

    127.0.0.1 localhost

    127.0.1.1 packer-virtualbox-iso

    127.0.0.1 nginx.local

Вещи работают и не работают

1. In host (i.e. a ubuntu host), access http://nginx.local, I am not able to access it.
2. In host, access http://localhost:8788 and http://localhost:222, both gave me "SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 Protocol mismatch."
3. In host, access 192.168.56.101, it works and php outputs something. (192.168.56.101 is pointing to /var/www/html/index.php in guest)

Цель:

Мне нужно получить доступ к http://nginx.local в хосте (http://nginx.local указывает на /var/www/nginx/index.php)

Файлы конфигурации

_.conf

server {
  listen                *:80;

  server_name           _;
  client_max_body_size 1m;

    index  index index.html index.htm index.php;

  access_log            /var/log/nginx/_.access.log;
  error_log             /var/log/nginx/_.error.log;

  location / {

    root  /var/www/html;
    try_files $uri $uri/ index.php /index.php$is_args$args;
  }
  location ~ \.php$ {

    root  /var/www/html;
    try_files $uri $uri/ /index.php /index.php$is_args$args$is_args$args;
    index  index.html index.htm index.php;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $request_filename;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
  }
  sendfile off;
}

nginx.local.conf

server {
  listen                *:80;

  server_name           nginx.local www.nginx.local;
  client_max_body_size 1m;

    index  index.html index.htm index.php;

  access_log            /var/log/nginx/nginx.local.access.log;
  error_log             /var/log/nginx/nginx.local.error.log;

  location / {

    root  /var/www/nginx;
    try_files $uri $uri/ index.php /index.php$is_args$args;
  }
  location ~ \.php$ {

    root  /var/www/nginx;
    try_files $uri $uri/ /index.php /index.php$is_args$args$is_args$args;
    index  index.html index.htm index.php;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $request_filename;
    fastcgi_param APP_ENV dev;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
  }
  sendfile off;
}

server {
  listen       *:443 ssl spdy;

  server_name  nginx.local www.nginx.local;

  ssl on;

  ssl_certificate           /etc/nginx/nginx.local.crt;
  ssl_certificate_key       /etc/nginx/nginx.local.key;
  ssl_session_cache         shared:SSL:10m;
  ssl_session_timeout       5m;
  ssl_protocols             SSLv3 TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers               HIGH:!aNULL:!MD5;
  ssl_prefer_server_ciphers on;
  client_max_body_size 1m;
    index  index.html index.htm index.php;

  access_log            /var/log/nginx/ssl-nginx.local.access.log;
  error_log             /var/log/nginx/ssl-nginx.local.error.log;


  location ~ \.php$ {

    root  /var/www/nginx;
    try_files $uri $uri/ /index.php /index.php$is_args$args$is_args$args;
    index  index.html index.htm index.php;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $request_filename;
    fastcgi_param APP_ENV dev;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
  }
  location / {

    root  /var/www/nginx;
    try_files $uri $uri/ index.php /index.php$is_args$args;
  }
  sendfile off;
}

vagrant.yml

vagrantfile-local:
    vm:
        box: puphpet/ubuntu1404-x64
        box_url: puphpet/ubuntu1404-x64
        hostname: ''
        memory: '996'
        cpus: '1'
        chosen_provider: virtualbox
        network:
            private_network: 192.168.56.101
            forwarded_port:
                8qJNnHDASTvX:
                    host: '8788'
                    guest: '22'
        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:
            KnaMKswBsqau:
                owner: www-data
                group: www-data
                source: /my_host_path_to/var/www
                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:
        - vim
        - htop
firewall:
    install: '1'
    rules: null
apache:
    install: '0'
    settings:
        user: www-data
        group: www-data
        default_vhost: true
        manage_user: false
        manage_group: false
        sendfile: 0
    modules:
        - rewrite
    vhosts:
        GHWEbSSEqbWY:
            servername: awesome.dev
            serveraliases:
                - www.awesome.dev
            docroot: /var/www/awesome
            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
nginx:
    install: '1'
    settings:
        default_vhost: 1
        proxy_buffer_size: 128k
        proxy_buffers: '4 256k'
    upstreams: {  }
    vhosts:
        0cRd9MwEYDPP:
            proxy: ''
            server_name: nginx.local
            server_aliases:
                - www.nginx.local
            www_root: /var/www/nginx
            listen_port: '80'
            location: \.php$
            index_files:
                - index.html
                - index.htm
                - index.php
            envvars:
                - 'APP_ENV dev'
            engine: php
            client_max_body_size: 1m
            ssl: '1'
            ssl_cert: ''
            ssl_key: ''
            rewrite_to_https: '0'
            spdy: '1'
php:
    install: '1'
    version: '56'
    composer: '1'
    composer_home: ''
    modules:
        php:
            - cli
            - intl
            - mcrypt
        pear: {  }
        pecl:
            - pecl_http
    ini:
        display_errors: On
        error_reporting: '-1'
        session.save_path: /var/lib/php/session
    timezone: Australia/Melbourne
    mod_php: 0
hhvm:
    install: '0'
    nightly: 0
    composer: '1'
    composer_home: ''
    settings:
        host: 127.0.0.1
        port: '9000'
    ini:
        display_errors: On
        error_reporting: '-1'
    timezone: null
xdebug:
    install: '1'
    settings:
        xdebug.default_enable: '1'
        xdebug.remote_autostart: '0'
        xdebug.remote_connect_back: '1'
        xdebug.remote_enable: '1'
        xdebug.remote_handler: dbgp
        xdebug.remote_port: '9000'
xhprof:
    install: '0'
wpcli:
    install: '0'
    version: v0.17.1
drush:
    install: '1'
    version: 6.3.0
ruby:
    install: '1'
    versions:
        daUbcwMPSTjQ:
            version: 2.1.2
            bundler: '1'
nodejs:
    install: '1'
    npm_packages: {  }
python:
    install: '1'
    packages: {  }
    versions:
        qUZ7yBqq97GX:
            version: ''
mysql:
    install: '1'
    override_options: {  }
    root_password: 'pass'
    adminer: 0
    databases:
        93drU219cTxI:
            grant:
                - ALL
            name: dbname
            host: localhost
            user: dbuser
            password: 'pass'
            sql_file: ''
postgresql:
    install: '0'
    settings:
        root_password: '123'
        user_group: postgres
        encoding: UTF8
        version: '9.3'
    databases: {  }
    adminer: 0
mariadb:
    install: '0'
    override_options: {  }
    root_password: '123'
    adminer: 0
    databases: {  }
    version: '10.0'
sqlite:
    install: '0'
    adminer: 0
    databases: {  }
mongodb:
    install: '1'
    settings:
        auth: 1
        port: '27017'
    databases: {  }
redis:
    install: '1'
    settings:
        conf_port: '6379'
mailcatcher:
    install: '0'
    settings:
        smtp_ip: 0.0.0.0
        smtp_port: 1025
        http_ip: 0.0.0.0
        http_port: '1080'
        mailcatcher_path: /usr/local/rvm/wrappers/default
        from_email_method: inline
beanstalkd:
    install: '0'
    settings:
        listenaddress: 0.0.0.0
        listenport: '13000'
        maxjobsize: '65535'
        maxconnections: '1024'
        binlogdir: /var/lib/beanstalkd/binlog
        binlogfsync: null
        binlogsize: '10485760'
    beanstalk_console: 0
    binlogdir: /var/lib/beanstalkd/binlog
rabbitmq:
    install: '0'
    settings:
        port: '5672'
elastic_search:
    install: '0'
    settings:
        java_install: true
        autoupgrade: true
Теги:
nginx
vagrant

1 ответ

0
Лучший ответ

Вы думаете об этом наоборот.

Вам нужно добавить nginx.local в основной файл хозяина ПК, а не в виртуальные машины.

192.168.56.101 nginx.local www.nginx.local

Этого должно быть достаточно. VM уже знает nginx.local благодаря nginx.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню