17

Here is my scenario:

Apache is running perfectly with SSL enabled and certs installed on port 443.

I would like to install nginx as well on the same machine. Both as a functional reverse proxy and a server on port 81 or 8443 (using the same cert used by apache)

I found plenty of solutions with nginx as primary server and apache as secondary. I don't want to mess with my existing apache configuration, so nginx will be secondary for me.

2
  • 1
    So what is your question? If you've already found plenty of solutions, I don't understand what you are asking for here.
    – terdon
    Feb 13, 2017 at 16:15
  • Yes its possible, apache is main and send static pages to nginx. Feb 13, 2017 at 16:18

1 Answer 1

13

Apache and Nginx can definitely run simultaneously. The default config will not allow them to start at the same time because they will both try to listen on the same port and the same IP.

However, you can easily either change the ports or ports and IPs, or IPs. There are various ways to make them run either one behind the other(usually Apache behind Nginx because Nginx will be the first entry point in the chain since it's faster for static resources, and Apache will then only be triggered for some advanced dynamic rendering/processing) or just side by side. Check this to start with: http://kbeezie.com/apache-with-nginx/

3
  • "The default config will not allow them to start at the same time because they will both try to listen on the same port and the same IP.": I don't normally working with webservers or networking side, so for added context to better understand the linked article, can you shortly explain why this is a problem (or a link to somewhere explaining)? Jun 18, 2021 at 20:07
  • 2
    @lampShadesDrifter it's the equivalent of expecting the same door (port) in the same house (IP) to open to two different rooms (app). How would you know which room you're going to get when you open the door? You need to give one or the other a different door (port). Mar 20 at 15:16
  • @lampShadesDrifter: Casey explained very well why you can't conceptually have 2 services listening to the same port. But, on the practical side: it's a problem because the OS will not allow it. The service that tries to listen to a port that's already taken will exit with an error message.
    – MestreLion
    Jun 9 at 3:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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