Here is How To Configure Nginx as a Reverse Proxy for Apache on HP Cloud Instance Running Ubuntu or Any Deb GNU/Linux. Both listen to port 80. We talked about Reverse Proxy and Reverse Proxying with Nginx Before. This is not a fully new users’ guide.
Configure Nginx as a Reverse Proxy for Apache : Specific For HP Cloud
Router, Subnet settings should be set properly to allow Port 80 Ingress and Egress.
If we run Apache behind Nginx, then the Port will be 8080. This is for who do not want to use PHP via FastCGI i.e. run a separate PHP5-FPM process.
---
If we configure for Side by Side running, we will use Port 80. Side by Side running needed when the web software does not support Nginx. If need to update the NameVirtualHost directive with IP in this case.
Configure Nginx as a Reverse Proxy for Apache
First we need to install Nginx :
1 2 | apt-get install nginx # apt-get install nginx-full |
First we need edit the /etc/nginx/sites-available/default
file :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | server { listen 80; # /usr/share/nginx/html; root /var/www/; server_name thecustomizewindows.com; index index.php index.html index.htm; server_name thecustomizewindows.com; access_log logs/nginx_access.log; error_log logs/nginx_error.log; location / { try_files $uri $uri/ @backend; } location @backend { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $host; proxy_pass http://127.0.0.1:8080; # proxy_pass http://10.0.0.1:8080; } location ~ /\.ht { deny all; } } |
If Nginx fails then it will pass the request to Apache2. Be careful about the listen 80;
directive. Test with commenting it out and running nginx -t
.
Now we will install Apache2 :
1 | apt-get install apache2 |
We have edit two files, one is /etc/apache2/ports.conf
:
1 2 | NameVirtualHost 127.0.0.1:8080 Listen 127.0.0.1:8080 |
Second, we have copy the default file, edit the port to 8080
:
1 2 | cp /etc/apache2/sites-available/default /etc/apache2/sites-available/thecustomizewindows nano /etc/apache2/sites-available/thecustomizewindows |
That file should have :
1 | <VirtualHost 127.0.0.1:8080> |
Apache2 virtual host should be corrected to have the same web root :
1 2 3 4 5 | <VirtualHost> DocumentRoot "/var/www/" ServerName thecustomizewindows.com ... </VirtualHost> |
Now activate it :
1 | sudo a2ensite thecustomizewindows |
thecustomizewindows
is just a name used. Then we can install PHP5 and restart the services :
1 2 3 | apt-get install php5 service apache2 restart service nginx restart |