Does nginx forward requests to backend servers using http or https?


#1

I am using the free version of nginx on RHEL 6.7. The version is :

nginx-1.10.1-1.el6.ngx.x86_64

When using nginx as a load balancer I would like to know if nginx
forwards requests to backend servers using http or https??


#2

You define what you want it sent to the backend as. So if you use
http://backendserver it’s http, if https://backendserver:443 - https.


#3

Are you referring to the proxy pass declaration? If so I get an error
when I uncomment that line out saying “nginx: [emerg] “proxy_pass”
directive is not allowed here in /etc/nginx/conf.d/default.conf:40?”


From: nginx removed_email_address@domain.invalid on behalf of Drew Turner
removed_email_address@domain.invalid
Sent: Tuesday, July 5, 2016 9:33 AM
To: removed_email_address@domain.invalid
Subject: Re: does nginx forward requests to backend servers using http
or https?

You define what you want it sent to the backend as. So if you use
http://backendserver it’s http, if https://backendserver:443 - https.

On Tue, Jul 5, 2016 at 9:26 AM, Brian Pugh
<removed_email_address@domain.invalidmailto:removed_email_address@domain.invalid> wrote:

I am using the free version of nginx on RHEL 6.7. The version is :

nginx-1.10.1-1.el6.ngx.x86_64

When using nginx as a load balancer I would like to know if nginx
forwards requests to backend servers using http or https??


#4

Yes that is in proxy_pass. Are you sure proxy_pass is defined in the
server stanza and that it’s inside an include stanza?

Posting the code would be helpful if you can redact the sensitive
information.


#5

Yes, However I did not have the entire stanza un-commented out. I have
done
that, but now I am encountered with a different error message. Now I
get:

nginx: [emerg] host not found in upstream “resolveservergroup.com” in
/etc/nginx/conf.d/default.conf:40

Here is my default.conf file:

upstream backendservergroup.com {
# Use ip hash for session persistance
ip_hash;
# backend server 1
server 192.168.155.120;
# backend server 2
server 192.168.155.126;
# backend server 3
server 192.168.155.127;

    # The below only works on nginx plus
    #sticky route $route_cookie $route_uri;

}
server {

listen       80;
server_name  nginxserver.com;
keepalive_timeout 70;

#charset koi8-r;
#access_log  /var/log/nginx/log/host.access.log  main;

location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
location ~ \.php$ {
    proxy_pass   http://backendservergroup.com;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}

}

server {

listen       443 ssl;
server_name  nginxserver.com;
keepalive_timeout 70;

#charset koi8-r;
#access_log  /var/log/nginx/log/host.access.log  main;

location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
location ~ \.php$ {
   proxy_pass   https://backendservergroup.com:443;
   proxy_http_version 1.1;
   proxy_set_header Connection "";

}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}

#6

can you move the backend server declaration from your .conf file to the
nginx.conf file inside the http stanza?