How can I use Apache as a reverse proxy for https?

What is an Apache reverse proxy?

An Apache reverse proxy is a web server that acts as a front end for other web servers.

The purpose of a reverse proxy is to route HTTP requests to a different server, based on the URL. For example, if you have a website that you are hosting with a hosting service, such as HostGator, it may be hosted behind a different sub-domain of HostGator. However, if you are interested in using a different site for different users (eg mobile vs. Desktop), you could use a reverse proxy to redirect all HTTP requests from mobile devices to a different website.

When you deploy an Apache reverse proxy, you are telling your web server to forward requests to another server. You do this by telling your Apache server to listen on a different port number than what it normally listens on.

Here is an example of how a reverse proxy works: Your web server, Apache they will be directed to the web server running on port 8080. If a user accesses they will be directed to the web server running on port 80.

Configuring Apache reverse proxies. In order for a reverse proxy to work, it requires two things: Apache must listen on the new port and forward the request to the backend server. The backend server must listen on the new port and respond to the request. The most common way to configure Apache reverse proxies is through a virtual host. A virtual host is simply a name that the web server uses to direct traffic to a particular backend server.

The following example shows how a reverse proxy works with a virtual host: ServerName example.com ServerAlias www.com ProxyPass / ProxyPassReverse /

This example tells Apache to listen on port 8080 and forward any requests to the backend server on port 80. It also tells the backend server to listen on port 8080 and to respond to requests on that port.

Note that in the above example, the backend server has the name localhost. This means that only requests to that server will be handled.

Which is better for reverse proxy, nginx or Apache?

I am developing a website that's currently hosted on an Amazon EC2 instance with nginx running in reverse proxy mode.

I am now looking at moving my website to a dedicated server on Amazon EC2, but I would like to know what is better, for performance, stability, speed etc. Apache, nginx or something else?

From my experience with both Apache and nginx I would say Nginx for a number of reasons. The first is that Nginx is much lighter weight than Apache and will therefore be much faster. Apache is known to be a memory hog and can also become bogged down when you have more connections than it can handle. (Apache also does not natively support SSL, which many consider to be a benefit)
Secondly, I would suggest reading over the nginx vs apache guide on their wiki.e. As well as this, I would suggest getting the nginx version 1.0.1 release candidate because that will include most of the features from the next release of Nginx. Some of these features include the new proxynextupstream module and the new workerconnections module. These modules can have a huge impact on how your website performs on the server.

Third, make sure that you are using SSL for your site. Nginx supports SSL natively out of the box. You can install the openssl package and then run the nginx binary with -k option to set the key file location. This way you can keep your private key on the server and it will be easier to manage.

I have also had a few bad experiences with running modphp under Nginx, so try to avoid this if possible.

Related Answers

What are the two types of proxies?

You can use a reverse proxy for multiple reasons, but mostly it is us...

Why is it called a reverse proxy?

What is the difference between a reverse proxy an...

Does Apache support reverse proxy?

I have a.war application which is deployed in the Tomcat server. br...