TechRemarker
TechRemarker

Reputation: 2938

Can a server run Nginx for some sites and Apache Nginx Reverse Proxy for others?

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?

Upvotes: 1

Views: 738

Answers (1)

Mohammad AbuShady
Mohammad AbuShady

Reputation: 42899

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>

Upvotes: 1

Related Questions