Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#569 closed defect (invalid)

[emerg] invalid host in upstream "http://phpbackend"

Reported by: Bruno Galindro da Costa Owned by:
Priority: major Milestone: 1.7
Component: nginx-module Version: 1.5.x
Keywords: upstream Cc:
uname -a: Linux SV-HOMOLOG 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.7.1
built by gcc 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/ --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --add-module=/root/headers-more-nginx-module-0.25/


I'm trying to use upstream config to loadbalance my fastcgi requests to 4 php-fpm pools. But it seems that fastcgi_pass doesn't recognize upstream configuration, throwing an error when I exec nginx -t:

nginx: [emerg] invalid host in upstream "http://phpbackend" in /etc/nginx/includes/php5-fpm.conf:4
nginx: configuration file /etc/nginx/nginx.conf test failed

I'm using the last mainline version: 1.7.1.

My config is divided into 5 files:

# /etc/nginx/nginx.conf
user www-data;
worker_processes 2;
pid /run/;

events {
	worker_connections 4096;
	multi_accept on;
	use epoll;

http {

	upstream phpbackend { 
		server unix:/var/run/php5-fpm.sock1 weight=100 max_fails=5 fail_timeout=5; 
		server unix:/var/run/php5-fpm.sock2 weight=100 max_fails=5 fail_timeout=5; 
		server unix:/var/run/php5-fpm.sock3 weight=100 max_fails=5 fail_timeout=5; 
		server unix:/var/run/php5-fpm.sock4 weight=100 max_fails=5 fail_timeout=5; 

	# Stop Displaying Server Version in Configuration
	server_tokens off;

	# Let NGINX get the real client IP for its access logs
	real_ip_header X-Forwarded-For;

	include /etc/nginx/mime.types;
	default_type application/octet-stream;

	# Log Format
	log_format main '$remote_addr - $remote_user [$time_local] '
	'"$request" $status $body_bytes_sent "$http_referer" '
	'"$http_user_agent" "$http_x_forwarded_for"';

        # Logging Settings
	rewrite_log on;
        access_log syslog:server= main;
	error_log syslog:server=;

	# Gzip Settings
	gzip on;
	gzip_static on;
	gzip_disable "msie6";
	gzip_vary on;
	gzip_proxied any;
	gzip_comp_level 6;
	gzip_min_length 1100;
	gzip_buffers 16 8k;
	gzip_http_version 1.1;
	gzip_types text/css text/javascript text/xml text/plain text/x-component 
	application/javascript application/x-javascript application/json 
	application/xml  application/rss+xml font/truetype application/x-font-ttf 
	font/opentype application/ image/svg+xml;

	# Cache
	open_file_cache max=200000 inactive=20s; 
	open_file_cache_valid 30s; 
	open_file_cache_min_uses 2; 
	open_file_cache_errors on;

	# Client Timeouts
	client_max_body_size 500M; 
	client_body_buffer_size 1m; 
	client_body_timeout 15; 
	client_header_timeout 15; 
	keepalive_timeout 2 2; 
	send_timeout 15; 
	sendfile on; 
	tcp_nopush on; 
	tcp_nodelay on; 

	# Output buffers
	reset_timedout_connection on; 
	server_names_hash_bucket_size 100;

	# Virtual Host Configs
	include /etc/nginx/conf.d/*.conf;
	include /etc/nginx/sites-enabled/*;


# /etc/nginx/sites-enabled/

server {
	listen 80;
	include includes/;

server {
	listen 443;
	include includes/;
	if  ($http_user_agent ~ "MSIE [2-6]") {
		set  "$nokeepalive" 1;
		set  "$ssl-unclean-shutdown" 1;
		set  "$downgrade-1.0" 1;
		set  "$force-response-1.0" 1;

	if  ($http_user_agent ~ "MSIE [17-9]") {
		set  "$ssl-unclean-shutdown" 1;
	ssl  on;
	ssl_client_certificate  /etc/ssl/nginx/intermediate.crt;
	ssl_certificate  /etc/ssl/nginx/certificate.crt;
	ssl_certificate_key  /etc/ssl/nginx/private.key;

# /etc/nginx/includes/
more_set_headers "Server: $host";

root /home/www/;
index index.php;

location / {
	try_files $uri $uri/ $uri/index.php;

include includes/expires.conf;

location ~ index\.php {
	rewrite .* /index.php?rewrite=1 break;
        include includes/;

location ~* \.php$ {
	include includes/;
# /etc/nginx/includes/

include includes/php5-fpm.conf;
fastcgi_param PHP_VALUE "newrelic.appname=Nginx";
fastcgi_param DOCUMENT_ROOT /home/www/;
# /etc/nginx/includes/php5-fpm.conf
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass http://phpbackend;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_pass_request_body off;
client_body_in_file_only clean;
fastcgi_param REQUEST_BODY_FILE $request_body_file;
fastcgi_param SERVER_NAME $host;
fastcgi_buffers 256 16k; 
fastcgi_buffer_size 128k; 
fastcgi_connect_timeout 3s; 
fastcgi_send_timeout 120s; 
fastcgi_read_timeout 120s;

PHP-FPM is running correctly:

# ls -lh /var/run/php5-fpm.*
-rw-r--r-- 1 root root 4 Jun  3 13:43 /var/run/
srw-rw-rw- 1 root root 0 Jun  3 13:43 /var/run/php5-fpm.sock1
srw-rw-rw- 1 root root 0 Jun  3 13:43 /var/run/php5-fpm.sock2
srw-rw-rw- 1 root root 0 Jun  3 13:43 /var/run/php5-fpm.sock3
srw-rw-rw- 1 root root 0 Jun  3 13:43 /var/run/php5-fpm.sock4

What I'm doing wrong?

Change History (2)

comment:1 by Maxim Dounin, 10 years ago

Resolution: invalid
Status: newclosed

The "fastcgi_pass" can't use "http" as a protocol, hence the error.

Please make sure to use mailing list for further questions. Trac is a wrong place to ask questions, it's to report/track bugs.

comment:2 by Bruno Galindro da Costa, 10 years ago

I'm very sorry for this post Maxim... Next time I'll use mailling lists.

Note: See TracTickets for help on using tickets.