nginx + apache subdomain question

So I have a setup where nginx is acting as a frontend proxy to apache, so it's sending any *.php requests over to apache.

I'm trying to figure out the best way to create subdomains with this type of setup. The only way I could think of was to send requests to a subdomain over a different port listened on by apache, but I've been told that apache will create a new instance for each port listened on (though I'm not sure of this?). Is there a better way to do this?

2 Replies

Apache does create multiple instances of itself (or rather, it's just one instance, but that one instance will have several processes, AKA multiple children of that one instance). I don't know how apache handles different ports, but I know it will do this with vhosts – the more vhosts you have and the heavier the load on apache, the more children it has.

Unless you have a specific need to have both nginx and apache running at the same time, I wouldn't recommend doing that. There are reasons for having both running, but it will take up more resources on your Linode, and you're just adding an extra layer to your software. You basically will have nginx sending the php to apache, which will load a module to connect to php, which will then send the php files to php, then back to apache, then back to nginx. If you use something like fastcgi or php-fpm in nginx, you will apache from this. You'll still have a module being loaded to bridge nginx to php, but that module will be used by nginx directly rather than sending it to apache first in order to use it.

I don't know for sure about the effects of listening on multiple addresses/ports, but the number of children is not (directly) affected by the number of s or ServerNames. More traffic (or, more specifically, more simultaneous connections) causes more children, though, and generally speaking, more VirtualHosts means more traffic. But adding a VirtualHost that receives no traffic will not increase the number of children on its own.

For the original question, I usually just pass the Host: header along and use virtual hosting on the back-end web server.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct