Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Ansible to compile and configure Nginx inside a Vagrant box.

If I run curl http://localhost/ from inside the box I get the expected response (phpinfo()).

If I access the URL http://testapp:8080/ from my Mac host machine then I can't connect.

My configurations is as follows:

HOST: /etc/hosts testapp

HOST: vagrantfile

Vagrant.configure("2") do |config|

  config.vm.define "web" do |web_config| = "raring64"
    web_config.vm.box_url = "{{redacted}}/" "forwarded_port", guest: 80, host: 8080 "private_network", ip: ""

    web_config.vm.provision :ansible do |ansible|
      ansible.playbook = "devops/webserver.yml"
      ansible.hosts = "webservers"
      ansible.inventory_file = "devops/hosts"
      ansible.verbosity = "vv"
      ansible.verbose = "true"

    web_config.vm.provider "virtualbox" do |v|
      v.customize ["modifyvm", :id, "--memory", "256"]

GUEST: /etc/nginx-1.5.6/nginx.conf

user www-data www-data;
worker_processes  1;

error_log  /var/log/nginx/error.log;
pid        /var/run/;

events {
  worker_connections  768;
  multi_accept on;

http {

  include       /etc/nginx-1.5.6/mime.types;
  default_type  application/octet-stream;

  access_log    /var/log/nginx/access.log;

  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;

  keepalive_timeout  65;

  server_tokens off;

  gzip  off;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_proxied any;
  gzip_vary off;
  gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/json;
  gzip_min_length  1000;
  gzip_disable     "MSIE [1-6]\.";

  include /etc/nginx-1.5.6/sites-enabled/*;

GUEST: /etc/nginx-1.5.6/sites-enabled/testapp.conf

upstream phpbackend {
    server unix:/var/run/php-fpm-www.sock;

server {
    server_name  testapp;
    root  /web/testapp/public;
    index index.php;

    access_log  /var/log/nginx/webvg.access.log;
    error_log /var/log/nginx/webvg.error.log debug;

    location / {
        try_files $uri $uri/ /index.php?$query_string;

    location ~ \.php$ {
        fastcgi_pass phpbackend;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /web/testapp/public/$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_param CACHE_HOST;
        fastcgi_param CACHE_PORT 6379;
        fastcgi_param NEO_HOST;
        fastcgi_param NEO_PORT   7474;
        fastcgi_param SERVER_ENV dev;

    location ~ ^/(php_status|php_ping)$ {
        fastcgi_pass phpbackend;
        fastcgi_param SCRIPT_FILENAME /web/testapp/public/$fastcgi_script_name;
        include fastcgi_params;
        deny all;

    location /nginx_status {
        deny all;
        access_log off;

    location ~ /\.git {
        deny all;

Can anyone spot something obvious that I'm missing?

Many thanks

share|improve this question
Anything in nginx logs? Would tunnelling as a workaround solve your problem? What about doing the port forwarding using nginx? – Steve Bennett Oct 9 '13 at 12:38

It's possible I'm going mad, but I think your app is really on (and that should work from both host and guest, or from the host alone) rather than port 8080.

The 8080 reference refers to the port forward from the mac host, where localhost:8080 should work as it points to on the guest.

share|improve this answer
It's worth mentioning that localhost is not an especially good test to be running, as it leads to precisely this type of (non-)problem. – Falcon Momot Oct 10 '13 at 1:16
up vote 0 down vote accepted

So I have edited the /etc/hosts file to point to instead of the address defined in the vagrantfile and I can now access the website from the host machine.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.