Welcome! Log In Create A New Profile

Advanced

Nginx Load Balancing Redirecting to Host Server

Posted by libtech 
Nginx Load Balancing Redirecting to Host Server
August 30, 2024 01:10PM
Hi Community,
Nginx is new for me. I want to use it as a load balancer for two WordPress websites. I installed Ngnix on a Rhel9 server and created a loadbalancer.conf file in etc/nginx/cond.d/ with the below content. When I type the ngnix IP address in the browser, it redirects me to the host. The web servers' IPs are 192.168.1.106 and 211, and the Nginx IP is 192.168.1.226. When I enter the Ngnix IP in the browser, it redirects me to 106 or 211. I also tested by updating nginx.conf with the below content, but it does the same. Is there any other configuration file that needs to be updated?
upstream myapp1 {
server 192.168.1.106;
server 192.168.1.211;
}
server {
listen 80;
location / {
proxy_pass http://myapp1;
}
}

I appreciate your help!
Re: Nginx Load Balancing Redirecting to Host Server
August 31, 2024 07:58PM
I was able to fix the issue. I added SITEURL and HOME with the Nginx IP address in wp-config.ph file from both hosts and it fixed the issue. Just wanted to post the answer just incase someone is new like me and have similar issue.
define('WP_SITEURL','http://192.168.1.226');
define( 'WP_HOME', 'http://192.168.1.226' );

I have another question: Can someone help? I tried to search for it in the documentation, but I couldn't find it. I might not have used the right keyword. How can I use Nginx as a proper load balancer for all websites? I mean, how can I add other websites? For example, I have already added two WordPress websites, and the load balancing is fine. If I added two Nextcloud websites and Confluence websites, Do I need to use different ports for each web service? I mean, how can I have multiple entries in the same nginx config file?
Appreciate your help!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 154
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready