What is the name and location of the Nginx config file (htaccess equivalent)?
There are many tutorials on how to write Nginx rewrite rules to mimic Apache's .htaccess file but I can't confidently say I know what the name or location of this so-called Nginx config file actually is. I'm specifically looking for the Nginx config file that allows you to write server path and PHP directives. I'm using Ubuntu 12 linux and Codeigniter as my PHP framework.
Here's what I know so far:
- This file:
/etc/nginx/nginx.conf
despite its enticing name is apparently not the place for server directives. - This file:
/etc/nginx/sites-available/default
seems like what I need (i'm able to generate php errors specific to my app) but I can't get the Codeigniter-specific path routing correct. First of all, is this the "config" file/.htaccess equivalent everyone speaks of?
I use PHP with nginx on my development server with the following configuration:
in
/etc/nginx/nginx.conf
I added:include /etc/nginx/sites-enabled/*;
before the last}
.-
run the following commands to create your site configurations:
mkdir /etc/nginx/sites-available/ mkdir /etc/nginx/sites-enabled/ cp /etc/nginx/conf.d/default.conf /etc/nginx/sites-available/<site>
edit the site configuration, some possible configurations (this is what I referred to in my setup): http://kbeezie.com/view/nginx-configuration-examples/
-
link to the available site to enable it
ln -s /etc/nginx/sites-available/<site> /etc/nginx/sites-enabled/<site>
keep in mind that you can actually include files within the configurations almost anywhere, this makes creating multiple sites easy when you want to throw similar configurations together.
Yes, .htaccess is compareable to the server{}
block in nginx, but they are also very different. nginx has a much more lightweight approach to parsing configuration, and it will not scan site directories for additional configuration, only whatever is seen by nginx.conf, goes.