Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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:

  1. This file: /etc/nginx/nginx.conf despite its enticing name is apparently not the place for server directives.
  2. 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?
share|improve this question

migrated from stackoverflow.com Jul 31 '12 at 13:59

This question came from our site for professional and enthusiast programmers.

    
Your 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. –  nickb Jul 31 '12 at 3:17

1 Answer 1

I use PHP with nginx on my development server with the following configuration:

  1. in /etc/nginx/nginx.conf I added: include /etc/nginx/sites-enabled/*; before the last }.

  2. 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>
    
  3. edit the site configuration, some possible configurations (this is what I referred to in my setup): http://kbeezie.com/view/nginx-configuration-examples/

  4. link to the available site to enable it

    ln -s /etc/nginx/sites-available/<site> /etc/nginx/sites-enabled/<site>
    
  5. 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.

share|improve this answer
    
-@Andrew thanks lots of helpful information!, by default my /etc/nginx/nginx.conf file already has include /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... –  tim peterson Jul 31 '12 at 2:36
    
I 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. –  Andrew Bestic Jul 31 '12 at 2:41
    
thanks for the tip on checking out your questions. I'm thinking i'm understanding more now, thanks for the setting me on the path... –  tim peterson Jul 31 '12 at 2:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.