The local port is added during a move (302)


I recently installed and configured HaProxy with a NGinx server, but I have a problem, when my NGinx server moves the user (302), in the new location, it adds the local port.

Here’s a demonstration example :

If we take a folder tree like this

$ tree public_html
├── toto
│   └── index.html
├── index.html

When the user makes the following query, we’ll get this result :

$ curl -iL
HTTP/1.1 302 Found
content-length: 0
cache-control: no-cache

HTTP/2 301 
server: nginx/1.26.1
date: Wed, 26 Jun 2024 06:18:40 GMT
content-type: text/html
content-length: 169
strict-transport-security: max-age=16000000; includeSubDomains; preload;

curl: (7) Failed to connect to port 3333 after 10 ms: Couldn't connect to server

My configuration

HaProxy.cfg :

$ cat /etc/haproxy/haproxy.cfg
    log local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/
    maxconn     2048
    user        haproxy
    group       haproxy

    stats socket /var/lib/haproxy/stats

    ssl-default-bind-options ssl-min-ver TLSv1.2

    ssl-default-bind-ciphers PROFILE=SYSTEM
    ssl-default-server-ciphers PROFILE=SYSTEM

    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000

    mode http
    bind :80
    bind :443 ssl crt /etc/haproxy/certs/
    http-request redirect scheme https unless { ssl_fc }
    http-response set-header Strict-Transport-Security "max-age=16000000; includeSubDomains; preload;"


    balance roundrobin
    server server1 check

exemple.conf :

$ cat /etc/nginx/conf.d/
server {
	root /var/www/;
	index index.php index.html;

	access_log /var/log/nginx/;
    	error_log /var/log/nginx/;

    	location ~ \.php$ {
        	try_files $uri = 404;
        	fastcgi_pass unix:/run/php-fpm/www.sock;
        	fastcgi_index   index.php;
        	fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        	include fastcgi_params;


I suspect that I must have missed a step in the HaProxy configuration, but I can’t find on the internet how to correct this, I don’t know if you could help me?

Looks like nginx added that, so perhaps you should adjust your nginx configuration to prevent it from forcing absolute uri on redirects.

Try this in the server block of your nginx config:

absolute_redirect off;
1 Like

Thank you very much, it works!