The question is to ask for a possibility of making nginx conditionally redirect requests to other servers (by reverse proxy) or process the request by itself.
Here's the details.
I have a Raspberry Pi (RPi) running nginx + wordpress for 24*7 at home. I also have a laptop running Ubuntu for about 5 hours every night.
The wordpress on RPi is working great but it's slow (especially when it's working on php). So I would like to let the laptop help:
- If laptop is on, RPi's nginx redirects all requests to Ubuntu by reverse proxy;
- If laptop is off, RPi's nginx process the request as usual.
I wonder if it's possible to achieve this? If yes, how to configure RPi and Ubuntu?
The basic solution is, make nginx as a reverse-proxy with fail_timout, when it receives a request, it dispatch to the upstreams where Ubuntu has higher priority, and if Ubuntu is offline, RPi will handle the request by itself.
This requires:
Below is the details of configuration.
Note, in my configureation:
Mysql
Set
bind-address = 192.168.1.100
in/etc/mysql/my.cnf
, and make sureskip-networking
is not defined;Grant permission to RPi and Ubuntu in mysql's console:
Wordpress
Set DB_HOST correctly:
NFS
On RPi, install nfs-kernel-server, and export by
/etc/exports
To enable nfs server on RPi, rpcbind is also required:
On Ubuntu, mount the nfs (it should also be set in /etc/fstab to make it mount automatically)
Nginx
On RPi, make a new config file
/etc/nginx/sites-available/wordpress-load-balance
, with below parameters:On Ubuntu, it can use the same config file.
Now any request received by RPi's nginx server on port 443, it's dispatched to either Ubuntu or RPi's port 8000, where Ubuntu has much higher priority. If Ubuntu is offline, RPi itself can handle the request as well.
Any comments are welcome!