Questions about nginx

I have some questions for anyone running nginx on their VPS (or dedicated PS too I guess).

A member of the support staff mentioned something regarding automatic management of nginx not working with an admin account on a VPS, is this the case, or is it merely if the default nginx settings are changed (which requires the admin account in order to do this)?

Secondly, if I don’t have an admin account, can I still setup simple redirection rules? I currently have .htaccess for this purpose, but with simple rules only (basic redirects, no rewrite rules etc.).

Does nginx have the ability to set mime-types for files in certain locations? My site handles user uploaded files, and while I don’t believe there is a risk of them being executed, I still have a .htaccess file ensuring that scripts can’t be executed in case, just as an extra layer just in case. Can nginx do something like this?

Are the default settings for the number of PHP process similar to Apache? I’m currently happy with the number of PHP processes spawned for Fast CGI under Apache, and would like to keep that the same (it’s the number of other processes that Apache spawns which I’d like to cut down on). I only have a single user hosting domains, which I believe is important?

Lastly, does PHP still use settings under ~/.php/5.4/phprc when run under nginx? I would assume so, but just want to be sure.

Okay, so I just went ahead and tried it; I’m very pleased so far, as the memory use seems to be considerably more stable than apache was, with no apparent loss of performance, though PHP is my bottleneck so I didn’t expect that to change.

To answer some of my own questions; it seems that simply having an admin account means that Dreamhost won’t automatically manage nginx, I’m still not completely sure what the specifics of this are, but it meant that I decided not to setup an admin user for this reason, though it has introduced a couple of minor inconveniences.

The first was to do with setting up redirections etc.; fortunately this is nice and easy to do as you just need a $HOME/nginx/ folder for each domain you want to create rules for, and just add as many .conf files there as you like to keep the rules organised. The only difficulties that I discovered is that without an admin account you can’t restart nginx directly, which means you need to request a reboot which is slower (and limited to once per 15 minutes I believe). The other issue is that I couldn’t find a way to get at any of nginx’s logs, which makes validating settings difficult. In the end what I did was created a stripped down nginx configuration file that imported all the .conf files I wanted to test, and then ran the following command as a regular user:

The above command tells nginx to just test the settings provided, which it will do. You might get some errors about not being root, but it should highlight any syntax errors or broken rules that would prevent nginx from starting up after rebooting. Since a full reboot is required it will be very important to run tests in this way before changing any of the .conf files, otherwise you’re stuck without a web-server for 15 minutes till you can fix it and reboot again. If someone knows of a quicker method then I’d love to hear it!

I found how to modify file MIME types, in my case I did it with a standard rule with the add_header directive setting a different mime-type to ensure files are downloaded by default. It’s pretty easy to setup most rules actually, and I do think it’s better consolidating them into one place, as I didn’t realise how many separate .htaccess files I had!

Contrary to the wiki page though, I’ve used the following basic command for redirections:

I’m not sure if I should change the wiki? It sounds like the above may be a lot more efficient than the recommended if conditions with a rewrite command, or does the nginx startup process optimise that to be the same thing?

Oh, and PHP RC settings seem to work just fine, only thing is that I think nginx doesn’t respect the choice of PHP version for a domain, so I may be stuck in PHP 5.3, I tried a command from the wiki to change PHP versions but it didn’t appear to do anything, does anyone know of the correct process for changing this, or is it an admin-only feature?

Rather than change the wiki, you could append your information to it, nothing “This will also work…” and linking to this forum post, as well as adding a link to whatever external reference you found that information at.