Nginx as webserver for 1 website and apache for another. Is it possible

Apache2nginxweb-server

On a VPS with centos panel I've Apache as webserver and Nginx as reverse proxy.

I've heard that the second is faster than Apache to handle PHP requests and I'd like to configure it as WebServer for 1 website, but I still need Apache for another one.

Is it possible?

My goal is to speed up the serving time of php pages. For example wp-admin/admin-ajax.php takes 7 seconds to render!!! I would expect 0,5 seconds.

Best Answer

AFAIK you can't have two processes listening on the same port (80/http) on one machine, so probably not in parallel as such.

However you could have Nginx listening on port 80, Apache listening on another port (81), and have Nginx pass applicable requests to Apache. Each would then pass the request off to wherever it needs to go, PHP for example. However this is probably very similar to what you have now, so I'm not quite sure it's what you're looking for.

Perhaps if you describe your setup and goals a little more fully we could help more.

Update PHP being slow is unlikely to be with the web server. You'll need to look at the resources used, dig into the code, check logs, and see what's going on. You can use Nginx Page Caching or Microcaching for rapidly changing websites to massive increase the speed for anonymous users. Caching reduces server load so also reduces page generation time for logged in users.

PHP isn't the fastest language around, though if properly resourced it's ok. HHVM is another PHP interpreter that's faster than PHP5, but I found it didn't work well for Wordpress with the plugins I use. PHP7 is faster, but again I had trouble with some plugins.

You've said it takes 7 seconds to render the page. Have you done a test using something like webpagetest.org to determine what part of the page load is slow? It can help tell you if it's page generation, dependent resources, etc.

You should also consider a CDN, such as CloudFlare, which has an effective free tier.