Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.
This repository was archived by the owner on Oct 8, 2025. It is now read-only.

No native method to obtain client remote IP-address. #132

@lazovskiy

Description

@lazovskiy

Hello.

Unit does not considering X-Real-IP header for REMOTE_ADDR replacement.

unit config:

	"listeners": {
		"127.0.0.1:8080": {
			"application": "portal"
		}
	},

	"applications": {
		"iptvportal": {
			"type": "php",
			"processes": 10,
			"user": "portal",
			"group": "portal",
			"root": "/srv/www/vhosts/portal.local/public",
			"script": "index.php"
		}
	},

	"access_log": "/var/log/unit/access.log"
}

nginx.conf:

        root /srv/www/vhosts/portal.local/public;
        index index.html index.php;

        location / {
                try_files $uri @symfony;
        }

        location @symfony {
                proxy_pass http://127.0.0.1:8080;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $remote_addr;
        }

Unit access.log:

127.0.0.1 - - [13/Jun/2018:13:49:00 +0300] "GET / HTTP/1.0" 200 1790 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/66.0.3359.181 Chrome/66.0.3359.181 Safari/537.36"

var_dump($_SERVER):

array(27) {
  | ["SERVER_SOFTWARE"]=>
  | string(8) "Unit/1.2"
  | ["SERVER_PROTOCOL"]=>
  | string(8) "HTTP/1.0"
  | ["PHP_SELF"]=>
  | string(10) "/index.php"
  | ["SCRIPT_NAME"]=>
  | string(10) "/index.php"
  | ["SCRIPT_FILENAME"]=>
  | string(56) "/srv/www/vhosts/portal.local/public/index.php"
  | ["DOCUMENT_ROOT"]=>
  | string(46) "/srv/www/vhosts/portal.local/public"
  | ["REQUEST_METHOD"]=>
  | string(3) "GET"
  | ["REQUEST_URI"]=>
  | string(1) "/"
  | ["SERVER_NAME"]=>
  | string(23) "portal.local"
  | ["SERVER_PORT"]=>
  | string(2) "80"
  | ["REMOTE_ADDR"]=>
  | string(9) "127.0.0.1"
  | ["SERVER_ADDR"]=>
  | string(9) "127.0.0.1"
  | ["HTTP_HOST"]=>
  | string(23) "portal.local"
  | ["HTTP_X_REAL_IP"]=>
  | string(11) "10.0.43.213"
  | ["HTTP_X_FORWARDED_FOR"]=>
  | string(11) "10.0.43.213"
  | ["HTTP_CONNECTION"]=>
  | string(5) "close"
  | ["HTTP_CACHE_CONTROL"]=>
  | string(9) "max-age=0"
  | ["HTTP_UPGRADE_INSECURE_REQUESTS"]=>
  | string(1) "1"
  | ["HTTP_USER_AGENT"]=>
  | string(135) "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/66.0.3359.181 Chrome/66.0.3359.181 Safari/537.36"
  | ["HTTP_ACCEPT"]=>
  | string(85) "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
  | ["HTTP_ACCEPT_ENCODING"]=>
  | string(17) "gzip, deflate, br"
  | ["HTTP_ACCEPT_LANGUAGE"]=>
  | string(35) "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7"
  | ["REQUEST_TIME_FLOAT"]=>
  | float(1528886940.151)
  | ["REQUEST_TIME"]=>
  | int(1528886940)
  | ["argv"]=>
  | array(0) {
  | }
  | ["argc"]=>
  | int(0)
  | }

Seems that currently there is no implementation of these basic feature, so it is impossible to use Unit with PHP-scripts without code modifications.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    🚀 Released

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions