CherryPy can be integrated with other web servers like Apache or Nginx using different deployment strategies, allowing these servers to act as reverse proxies that forward requests to a CherryPy application.
Integration with Apache :
* Using mod_proxy : Enable mod_proxy: Ensure that the Apache server has mod_proxy enabled.
* Configure Apache : Set up a virtual host configuration in Apache and use the
ProxyPass
directive to forward requests to the CherryPy application's address.
Example Apache Virtual Host Configuration:
<VirtualHost *:80>
ServerName example.com
ProxyPass / http://127.0.0.1:8080/ # Forward requests to CherryPy
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>​
Using mod_wsgi : Another approach involves using mod_wsgi to serve a CherryPy application through Apache.
Integration with Nginx :
* Configure Nginx : Set up a server block in Nginx configuration and use the
proxy_pass
directive to forward requests to the CherryPy application's address.
Example Nginx Server Block Configuration :
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://127.0.0.1:8080; # Forward requests to CherryPy
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}​
Considerations :
When deploying CherryPy behind a reverse proxy (Apache or Nginx), the CherryPy server itself can run on a different port (e.g., 8080). The reverse proxy server (Apache or Nginx) listens on the standard HTTP/HTTPS port (80 or 443) and forwards requests to CherryPy.
Reverse proxies can provide additional functionalities like load balancing, caching, SSL termination, and security features.
Ensure proper configuration of headers like
X-Real-IP
and
X-Forwarded-For
to preserve the original client IP when requests pass through the reverse proxy.
CherryPy's ability to integrate with other servers through reverse proxy configurations allows for flexibility in deployment while leveraging the features and scalability offered by servers like Apache or Nginx.