Y
Y
YemSalat2015-08-26 17:05:45
Nginx
YemSalat, 2015-08-26 17:05:45

How to set up 1 nginx for many Apaches?

Hello,
I want to set up nginx as a proxy for Apache.
On Apache (hanging on port 8080), I have many virtual hosts (domains) installed, all on the same ip.
Is it possible to somehow "globally" configure nginx so that we don't have to create a separate server block for each host?
For example, if I have all these sites in folders by host name:
/var/www/mydomain.com/
/var/www/otherdomain.org/
...

Nginx will only have to return static, and send all other requests to Apache ( while passing the correct parameters, etc.)
If such a configuration is possible - do you think there could be any potential problems with it?
Thank you!
PS
For the admin panel, ISPconfig is used if anything (tied to Apache)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vlad Zhivotnev, 2015-08-26
@YemSalat

server {
    listen 80 default;
    disable_symlinks if_not_owner from=$root_path;
    set $root_path /var/www/$http_host;
    location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
      root $root_path;
      error_page 404 = @fallback;
    }
    location / {
      proxy_pass http://127.0.0.1:8080;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Real-IP $remote_addr;
    }
    location @fallback {
      proxy_pass http://127.0.0.1:8080;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Real-IP $remote_addr;
    }
  }

P
Puma Thailand, 2015-08-26
@opium

It's easier to proxy pass everything and set up the cache normally in the PACE proxy

I
Igor Vorotnev, 2015-08-26
@HeadOnFire

Nginx will have to give only static, and send all other requests to Apache (while passing the correct parameters, etc.)

Are there really good reasons to use Apache? Nginx perfectly knows how to proxy directly to the same PHP-FPM (for PHP), Passenger or Unicorn (for Ruby) and so on. Why Apache? Good old habit?
Is the slow, slow, resource-consuming Apache not enough for you?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question