Homestead: NGINX and Apache conflict

Created on 24 Apr 2017  路  6Comments  路  Source: laravel/homestead

Versions

  • Vagrant: 1.9.3
  • Provider: Virtualbox 5.1.20 r114629
  • Homestead: 5.2.3, box: 2.1.0

Host operating system

MacOS Sierra 10.12.4

Homestead.yaml

ip: "192.168.50.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys: [ ~/.ssh/id_rsa ]
folders:
    - map: ~/Projects/Playground/phpinfo
      to: /home/vagrant/phpinfo
    - map: ~/Projects/Playground/hello
      to: /home/vagrant/hello
sites:
    - map: phpinfo.app
      to: /home/vagrant/phpinfo/
      # type: apache
    - map: hello.app
      to: /home/vagrant/hello/
      type: apache
databases:
    - homestead
variables:
    - key: APP_ENV
      value: local

Vagrant up output

https://gist.github.com/zela/531b3fb6ef41a33e68fa2fab42c06bb3

Expected behavior

http://phpinfo.app shows phpinfo page
http://hello.app shows hello message

Actual behavior

Both http://phpinfo.app and http://hello.app show hello message
So Apache servers its site for both URLs

Going further

Reload vagrant

Expected behavior

http://phpinfo.app shows phpinfo page
http://hello.app shows hello message

Actual behavior

Both http://phpinfo.app and http://hello.app show phpinfo
Now nginx serves its site for both URLs!

Steps to reproduce

  1. Destroy proviously provisioned Homestead, to start form scratch
  2. Paste contents of Homestead. yaml
  3. Call vagrant up form Homestead directory
  4. Note bug part 1.
  5. Call vagrant reload form Homestead directory
  6. Note bug part 2. :)

So it鈥檚聽expectable, that since nginx is primary server for Homestead, it should proxy requests to Apache server for websites wich have type: apache and serve other types of websites normally.

Most helpful comment

Also, websites aren't accessible via https under Apache. Because mod_ssl isn't loaded.

I'd suggest to enable this stuff by default:

sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php7.1-fpm
sudo a2enmod ssl
sudo a2enmod proxy
sudo a2enmod rewrite

The most basic Homestead.yaml that works for testing:

ip: "192.168.50.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys: [ ~/.ssh/id_rsa ]
folders:
    - map: ~/Projects/Playground/phpinfo
      to: /home/vagrant/phpinfo
sites:
    - map: phpinfo-nginx.app
      to: /home/vagrant/phpinfo/
    - map: phpinfo-apache.app
      to: /home/vagrant/phpinfo/
      type: apache
variables:
    - key: APP_ENV
      value: dev

All 6 comments

This appears to be intended behavior. Homestead defaults to nginx when there is no site type by creating an nginx virtual host, not proxy to apache. They should both be served by apache when you uncomment the type from phpinfo.app

You will likely run into issues if you're trying to run apache AND nginx hosts on the same Homestead. I would recommend you use the per project install method OR use 1 Homestead for all of your apache projects, and one for all of your nginx projects.

Ok. So probably fix should be in documentation, to declare this incompatibility explicitly.
I was surprised by described behaviour since in some cases it's pretty viable solution to hide apache behind nginx, and supposed that it's supported in Homestead.

Thank you for blazing-fast answer!

We probably should have something in the types docs that mentions no type == nginx. The use case for Apache in Homestead is to use it as the primary server VS behind nginx. Because we're defaulting both vhosts to 80 mixing and matching is what would likely create conflicts.

@zela not sure if you are aware of the flip command that was added a month or two ago. You cannot run Apache and Nginx at the same time, so flip will turn off whichever one is active, and activate the other. I successfully run both Apache and Nginx sites on the same Homestead machine all the time, just have to remember to activate the appropriate web server for whichever site you are currently working on.

@browner12, thank you for the tip!

Note for future users:
I've found also that variables defined in Homestead.yaml don't work with Apache websites.
homestead.rb script adds them to ~/.profile and to /etc/php/7.1/fpm/php-fpm.conf.
PHP-FPM isn't enabled by default in Apache. Enabling it doesn't add environment variables. Looks like in this case it doesn't use config file mentioned above.

Also, websites aren't accessible via https under Apache. Because mod_ssl isn't loaded.

I'd suggest to enable this stuff by default:

sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php7.1-fpm
sudo a2enmod ssl
sudo a2enmod proxy
sudo a2enmod rewrite

The most basic Homestead.yaml that works for testing:

ip: "192.168.50.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys: [ ~/.ssh/id_rsa ]
folders:
    - map: ~/Projects/Playground/phpinfo
      to: /home/vagrant/phpinfo
sites:
    - map: phpinfo-nginx.app
      to: /home/vagrant/phpinfo/
    - map: phpinfo-apache.app
      to: /home/vagrant/phpinfo/
      type: apache
variables:
    - key: APP_ENV
      value: dev
Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattmcdonald-uk picture mattmcdonald-uk  路  3Comments

it-can picture it-can  路  3Comments

gormus picture gormus  路  4Comments

Modelizer picture Modelizer  路  5Comments

teleclimber picture teleclimber  路  3Comments