Search code examples
haproxy

how change my client request ip and forward to another website then return result to client with haproxy and dns


I have a domain name serve with a ha-proxy server. i want when the clients set my domain name server in their computer , when clients want to access ABC.com or def.com their request forward to my ha-proxy server then request sent to ABC.com or def.com (with ha-proxy server IP) and give it back to client.
i don't want all request send over my ha-proxy just when they want to access "ABC.com" or "def.com". I tried with "ngnix" and do just with one website but i cant do with two or more. any other solution will make me happier.


Solution

  • ok finally i did with nginx but problem exist with https website . here my ngnix configuration :

    
    
    server {
            listen 80;
            server_name www.myipaddress.com;
             location / {
                                    proxy_pass http://www.myipaddress.com:80;
                                    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;
                                    }
    }
    server {
            listen 80;
            server_name  myiplocator.net;
             location / {
                                    proxy_pass http://myiplocator.net:80;
                                    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;
    
                            }
    }
    
    

    but when i try with https website .https traffic doesn't go through my reverse proxy here my code :

    server {
            listen 443;
            ssl on;
            server_name www.oracle.com oracle.com;
            ssl_certificate     /etc/nginx/ssl/rpwildcard.crt;
            ssl_certificate_key /etc/nginx/ssl/rpwildcard.key;
             location / {
                                    proxy_bind 'mynetwork ip  interface';
                                    proxy_pass https://www.oracle.com;
                                    proxy_set_header Host $Host;
                                    proxy_set_header X-Real-Ip $remote_addr;