Hosting CodeIgniter inside a sub directory with Nginx
As I mentioned in my previous post, I had been setting up an old Codeigniter web app today in my local machine. This app was hosted with the Apache web server and it was running on PHP 5.6.
I tried to put this in a VM in my local machine using Vagrant. However, I faced some issues with this setup as I wanted to make it run with Nginx instead of Apache, and that too, inside a sub directory. The main problem I had was with the URL rewrites. In Apache, I was able to write an httaccess file and that would simply handle the rewrites.
However after some trial and error efforts, it turned out that it was really easy. Even easier than I actually thought. All I had to do was set the correct paths in the nginx config.
My CI app as residing inside a directory called 'admin'. So in my nginx host config file, I provided a location block as below.
location /admin {
try_files $uri $uri/ /admin/index.php?/$query_string;
}
and voila, it started working.
I thought of adding this to my blog as a note to myself. Anyway, If you ever come across this post, and have any issues, feel free to leave a comment.