Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache and Nginx both on port 80 [closed]

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?

like image 378
Passionate Engineer Avatar asked Dec 30 '12 15:12

Passionate Engineer


3 Answers

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.

like image 123
Thom Seddon Avatar answered Oct 29 '22 17:10

Thom Seddon


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.

like image 11
Trent Earl Avatar answered Oct 29 '22 18:10

Trent Earl


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.

like image 1
Eden Akhavi Avatar answered Oct 29 '22 18:10

Eden Akhavi