Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Ubuntu server 12. Apache, MySQL, PHP

I've only ever used Apache. I know how to set up the Virtual Hosts and all that. But I have no idea how to add NGINX to the mix and not ruin everything.

I'm playing with a testing server, so it's ok if something goes down temporarily. What I would like to do is have ONE (or a few) of the testing sites on the server use NGINX while the others still use Apache. Is that even a thing? Can I use both on one server?

If not, then what I'd like to do is be able to switch between using Apache and NGINX serverwide. Could I install NGINX and easily switch between the two?

e.g. could I just stop Apache, start NGINX and have everything work smoothly (assuming NGINX is configured properly)?

I'm about to install nginx and I just want to make sure it doesn't break any existing configurations.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Yeah, that will work fine - the problem is that they'll conflict in terms of listening on standard ports; both use port 80 by default.

To run them at the same time, configure one to listen on a different port - or to have them use the same port, just make sure you stop one before starting the other.

share|improve this answer
    
If I change the port for nginx, then I would have to actually specify that port on the client browser in order to get served by nginx, right? –  Buttle Butkus Dec 15 '12 at 21:05
    
@ButtleButkus Yes, or alternately, you can have Apache act as a reverse proxy and ProxyPass over to the nginx listener for certain sites or locations. –  Shane Madden Dec 15 '12 at 21:07
    
It seems like the 2-port solution would be better for testing the two HTTP servers side-by-side, since it doesn't involve any mixing between the two. That way I could access the same exact site with either HTTP server. Perhaps later I could use your reverse proxy solution for other tests, but it seems less "pure" since it "mixes" in some Apache. Although I suppose ProxyPass would probably be incredibly fast and not skew nginx performance significantly? –  Buttle Butkus Dec 15 '12 at 21:12
    
Also, I know this is a dumb question, but what is a safe port to use to not conflict with other services? All I have running right now is a simple LAMP stack but the last thing I want to do is assign a bad port# and break everything. –  Buttle Butkus Dec 15 '12 at 21:16
1  
If you're looking to do performance testing, don't reverse proxy. A common alternate port to use for HTTP is 8000 - it's unlikely that anything else will want to use that port. –  Shane Madden Dec 15 '12 at 21:34

Those are three questions, so you get three answers :)

  • Yes, you can run apache and nginx on the same server, provided they don't use the same source port/ip

  • Yes, you can make only one site use nginx. Easiest is to have multiple IP addresses so you can have an IP where nginx runs. Switching is then a matter of changing DNS records per site. Alternatively, you can run nginx on a different port. You can then even make apache forward to nginx so your customers don't see it (beware of logging issues, nginx thinks all connections come from localhost in this setup unless handled specially)

  • And finally, yes, if configured properly it's as simple as stopping apache and starting nginx (or vice versa) to switch between them. Configuring properly may take time though, depending on the compleity of the sites. The one-by-one approach sounds better to me

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.