Nginx config for hosting multiple projects in sibling folders

I have recently begun the process of migrating (laravel) apps into using Nginx+PHP-FPM.

Needless to say, it is definitely more challenging than configuring good ol Apache! For starters, you absolutely must know regular expressions fairly well. Nginx makes extensive use of regexes to figure out matching rules for urls. The second paradigm shift is learning that Nginx does configs on a “per-application” basis. What I mean is, you cannot just setup the server one time, and expect to drop in apps into the web folder, and hope things work (this is especially true for apps that use clean urls via htaccess rewrites). So, prior to setting up any web application, expect to work a bit on tweaking the Nginix config. The reward is a nimbler web server that performs much better under load.

I put together a config file that serves multiple Laravel applications stored in sibling folders (on a single server). So, http://192.168.33.10.xip.io/project1 will serve up application 1, and http://192.168.33.10.xip.io/project2 will serve up application 2.

/Vagrant is the root web folder, and /project1 and /project2 are sibling folders within the vagrant folder containing full laravel applications.

Hope you find this useful!

Advertisements

2 thoughts on “Nginx config for hosting multiple projects in sibling folders

    1. Hi John,
      Thanks for your comment.. I apologize for the omission. I have now added a bit of regex to handle static files. Please view the updated gist for details (also note slight modification to the request uri match)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s