I'm trying to install Nginx on my current cloud Cent OS server which has Apache httpd installed and running.
My hosting company tells me that Nginx and Apache can both run on port 80 at the same time so my plan was to transform .htaccess and Apache conf of Wordpress sites to Nginx after installing it via Yum.
I also Googled about this and some people suggest using Nginx as a reverse proxy and serve static files only but run Apache with PHP because Apache has PHP embedded and would consume less memory even though it doesn't support multiple concurrent requests like Nginx.
My gut feeling is that switching everything over to Nginx would be beneficial but unsure at this stage.
Also, is there anything I should watch out for when doing this switch over?
What would you do if it was you in this situation?
I'm not quite sure what your hosting company means by their comment but you won't be able to run BOTH Apache and Nginx on port 80. Once one is bound to port 80 the other will be unable to bind to it.
Probably the best configuration in your current situation would be to put Nginx on port 80 and Apache on 8000 or similar.
Use nginx to serve static files (see try_files because "if" is evil) and then proxy all requests for PHP to port 8000 using the HTTP proxy module.
The other common configuration for PHP with Nginx is to use PHP-FPM and proxy via FastCGI, just google "PHP-FPM Nginx {Your OS} tutorial" for a tutorial.
There much debate about the performance of PHP-FPM/mod_php but in my personal experience I have found PHP-FPM more performant.
I would use nginx as the web facing server on port 80 and proxy pass to apache which would be running on a different port. Many sites run this configuration. Serving static files with nginx is much more efficient than with apache. It is actually a lot simpler than it may sound.
This document explains in detail.
You should bind your externally facing webserver to the public IP address and the internally facing webserver to localhost (127.0.0.1:80).
So if you are using Nginx publicly then bind that to the public IP address and have it proxy to Apache at localhost.
Its better to use separate ports to make it easier to debug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With