1
votes

On a server ideally I'd serve my own static and WordPress sites using Cloudflare > Varnish > Nginx but since I'd also be hosting others sites for testing such as Joomla and WordPress that rely on multiple extensions that use .htaccess and such, I wouldn't be able to easily run those sites through Nginx. So I'd like to run those sites on the same server with CloudFlare > Varnish > Nginx Reverse Proxy > Apache.

The server only has 1 ip address and runs ubuntu and php-fpm and mysql. Each site would have their own separate domain name. Would this be possible?

1
Haven't heard yay or nay from anyone here. Tried on Twitter and someone mention it shouldn't be a problem, running some sites with nginx and some sites/domains running apache with nginx reverse proxy. Hopefully someone here will be able to confirm that. Then I'll simply have to do more research on how to implement it on my own.cchiera
Not sure what the problem is: You can of course serve more than one site through nginx. And you can configure each of them separately. So: Yes, you can.Michael Härtl
just install apache and run it on a different port, and proxy_pass them from nginx to apache's portMohammad AbuShady
@MichaelHärtl Right, but my issue isn't can I serve multiple sites through nginx, my question above is can I server some through regular nginx such as example1.com and example2.com but then server example3.com and example4.com through nginx reverse proxy to apache. (on the same server). Modammad Would your solution work in that scenario? I'm not familiar with proxy_pass but if it would please add it as an answer.cchiera
*in above comment meant "can I serve / but then serve" not "can I server / but then server"cchiera

1 Answers

0
votes
server {
    server_name example.com;
    location / {
        # assuming apache is on port 81 for example
        proxy_pass http://127.0.0.1:81;
        # to make apache detect the host header
        proxy_set_header Host $host;
    }

# if you have assets folders, you can let nginx serve them directly,
# instead of passing them to apache

    location /images { # or /css or /js .. etc
        try_files $uri =404;
    }
}

Note: in the case of assets, sometimes some sites serve assets through rewrites, or even handled by the application it self, you can pass it to apache by adding that in the assets location as a fallback like this

location /images {
    try_files $uri @apache;
}
location @apache {
    proxy_pass http://127.0.0.1:81;
}

In apache you create a virtual host

<VirtualHost *:81>
    ServerName example.com
    # the rest of the config if needed
</VirtualHost>