What is the name and location of the Nginx config file (htaccess equivalent)?
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.
Related videos on Youtube
tim peterson
web programming-javascript, php, mysql, css, html-is my thang
Updated on September 18, 2022Comments
-
tim peterson over 1 year
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?
-
nickb over 11 yearsYour problem isn't with PHP the language (i.e programming in PHP), it's with PHP configuration on a specific server, which explains the completely valid close votes. I cannot comment on the latter part of your post, as it seems highly subjective and biased.
-
bucabay about 8 yearsYou can find where nginx config is located using
nginx -V
which you can find in the manual withman nginx
. The-V
option is documented as "-V Print the nginx version, compiler version, and configure script parameters.". Ifnginx
is not in your path, usewhich nginx
which returns the full path to nginx$(which nginx) -V
- This file:
-
tim peterson over 11 years-@Andrew thanks lots of helpful information!, by default my
/etc/nginx/nginx.conf
file already hasinclude /etc/nginx/sites-enabled/*;
at the very end. It looks like these 2 files are talking to each other on my server and now I'm dealing with Codeigniter-specific issues. Are you using codeigniter? There is some path funkiness that I need to get a handle on... -
abestic9 over 11 yearsI use my own framework which is quite similar (albeit more primitive) to CodeIgniter. At the moment I am trying to get my mod_rewrite regexp rules converted to nginx's HttpRewrite module. My first major breakthrough was getting past the 403/404 errors nginx displays when I have incorrectly configured the
root
parameter. Feel free to check out my Questions if you need any inspiration. -
tim peterson over 11 yearsthanks for the tip on checking out your questions. I'm thinking i'm understanding more now, thanks for the setting me on the path...