This project contains everything necessary to set up a Vagrant box running an ASP.NET web server on Ubuntu, using Mono, Nginx and FastCGI Mono. It uses a package generated by the vagrant-mono repository as a base box.
Important note: The ./build-support/server-files/init.d/monoserve
file needs to have Unix-style line endings, otherwise you will get a cryptic : File does not exist
error when trying to start up the FastCGI Mono server. If you're running Windows and have GIT configured to automatically manage text file line endings (their default recommended setting on Windows), GIT will change the line endings on this file to Windows-style CR/LF when you clone the repository, resulting in the aforementioned error when the file is copied to your Vagrant box running Linux. I personally find this setting to be more trouble than it's worth and prefer to manage my own line endings because any reasonably good IDE or text editor understands Unix-style line endings. To turn off this setting, run the follwing command from the command prompt (eg, by running GIT Bash if you have GIT for Windows installed).
git config --global core.autocrlf false
- Install VirtualBox - NOTE: If you are running on Windows 8 please make sure not to install the network drivers, as explained in this post: http://www.grumpydev.com/2013/06/19/windows-8-hyper-v-virtualbox-vagrant-and-hanging-on-boot/
- Install Vagrant from http://www.vagrantup.com/
- Install the vagrant-mountcommand plugin for Vagrant by running
vagrant plugin install vagrant-mountcommand
. This is to work around a current limitation with running commands at boot time that need to run after Vagrant mounts the /vagrant shared folder. See here for more details.
Once you have the prerquisites installed and have built and installed the vagrant-mono
base box, do the following:
git clone git://github.com/chilimangoes/vagrant-mono-nginx.git
cd vagrant-mono-nginx
vagrant up
Provisioning your new development server will take a few minutes. When it's done, you will need to restart the server by issuing a vagrant reload
command. When your box comes back up, your development server will be ready. You can run vagrant ssh
to connect to the box and start using it.
If you navigate to http://localhost:8093/Default.aspx you should see a test page.
Out of the box, the ./src/WebProject
directory in this repository will be mounted as /var/wwwroot
on the server. When you add/remove/edit files in this directory, your changes will be reflected at the URL above. If you change the name of this folder from WebProject
to something else, you will need to edit the $WEB_PROJECT_FOLDER
variable in the Vagrantfile.
Note: Shared folders in VirtualBox have a bug where files that are modified on the host system do not trigger file system events in the guest, and vice-versa. Because Nginx and FastCGI Mono listen for these events to trigger updating resources, recompiling ASPX pages, reloading DLLs, etc, this causes changes made locally to not show up unless the web server is restarted. To work around this issue, a script is installed which monitors /var/wwwroot for changes and issues a touch /var/wwwroot
command to trigger a file system event that Nginx and FastCGI Mono can pick up. By default, this script (./build-support/server-files/development/wwwroot-watcher.sh) is set to rescan for changes every 5 seconds. This value can be adjusted based on your project size to balance responsiveness to changes with the performance impact that scanning for changes might have on a large directory tree.
The Vagrantfile and setup scripts used here are based on code and examples from various locations:
- http://www.philliphaydon.com/2013/06/setting-up-mono-on-nginx/
- http://alexfalkowski.blogspot.com/2013/03/web-development-on-mono.html
- http://stackoverflow.com/questions/12188356/what-is-the-best-way-to-run-servicestack-on-linux-mono
- http://jokecamp.wordpress.com/2013/06/30/servicestack-api-with-fastcgi-mono-server-and-nginx-hosted-on-digitalocean/
- http://www.without-brains.net/blog/2012/08/12/add-your-own-customization-to-vagrant-boxes/