We have a managed VPS (Virtuozzo + 512MB RAM) running cPanel+Apache+suphp and don't have any active site on it. Now we are planning to start an active image gallery on the VPS, so I am thinking of moving apache from port 80 and put Nginx in front but I am not sure about following things,
- If we put Nginx in front and use Apache on back serving PHP, will we be getting the actual user details (ip etc.) in Apache/PHP or we will be getting the ip of the Nginx proxy?
- I also want Nginx to serve the static contets/assets, but I think in this approach we will be serving images and other static contents with cookies as Nginx is listening for the main site and returning response from apache, so is there any way to send the assets using a cookie-free domain?
- Is it possible for us to later add another VPS and use the same Nginx to load balance between the current VPS and new VPS?
- Lastly, is it possible for Nginx to serve complete page or partial pages using a cache?
Would take load off Apache for serving the static files and nginx can do this more efficiently.
If you want real performance I'd suggest nginx+PHP-FPM setup which is atleast twice faster that classic Apache+PHP/nginx+Apache+PHP setups.
the support of separate configs in nginx+PHP-FPM isn't good. we can load multiple configs in nginx, but any change in any config will require a nginx reboot.
also my host don't provide full support of nginx, and also right now apache has far more community support compared with nginx.
You are right about nginx for serving static contents, but I am more interested in knowing about cookies. When browser sends a request to web server, the header contains cookies, browser-related fields, requested URL and refferer URL.
So I am interested in a way to use nginx to rewrite all the static content request to a special subdomain and serve the static contents using that sub-domain automatically.
Having your static files in a seperate subdomain will also have nginx to serve the static content from that location, however any PHP requests will be handed to PHP, cookies, sessions and everything related goes trough PHP, as it sets it, not Apache nor nginx.
Also, I forgot to mention to use mod_rpaf module for Apache to get the real IP address of the visitor, so you stat logs will be more accurate
Also, separate configurations loaded into nginx and PHP-FPM pools are running quite fine on several of mine servers and after fine tuning they're able to server a lot of requests at the same time.
i have used it on several boxes and it works well...It also integrates into WHM so you can stop, start and rebuild the vhost right from whm. It also does all the modification as far as modifying the ports needed to proxy back to apache.
the reason I want the rewriting instead of moving the actual files in a subdomain is
- easy to install any applications and the rewriting will automatically convert the paths without any modification.
- no need to create sub-domain manually