Can I run nginx and apache at the same time?

40,370

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/

Share:
40,370

Related videos on Youtube

Sands
Author by

Sands

Updated on September 18, 2022

Comments

  • Sands
    Sands over 1 year

    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.

    • Admin
      Admin about 7 years
      So what is your question? If you've already found plenty of solutions, I don't understand what you are asking for here.
    • Admin
      Admin about 7 years
      Yes its possible, apache is main and send static pages to nginx.
  • lampShadesDrifter
    lampShadesDrifter almost 3 years
    "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)?
  • Casey Murray
    Casey Murray about 2 years
    @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).
  • Admin
    Admin almost 2 years
    @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.