basic nginx setup help as load balancer

NdridCold . project722 at gmail.com
Tue Jul 5 16:11:48 UTC 2016


  I was getting a host not found problem while trying to start nginx.

nginx: [emerg] host not found in upstream "backendservers.com" in
/etc/nginx/conf.d/default.conf:37

I am fairly certain that this is because there is no name resolution for "
backendservers.com" in our DNS. So I changed up a few things to make it
work.

But I am confused on a few concepts here. First of all, should my server
name in the "upstream" directive be the same name in the "server_name"
directive in the "server" stanza? Here is what I have so far:


upstream myapplication.net {
        # Use ip hash for session persistance
        ip_hash;
        server 1.net;
        server 2.net;
        server 3..net;

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

    listen       80;
    server_name  myapplication.net;
    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://myapplication.net;
        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  myapplication.net;
    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://myapplication.net;
       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;
    #}

So here is what I need to happen. I need nginx to asnwer requests for
myapplication.net and send them to the servers "server1,net, server2.net,
and server3.net". Am I  accomplishing this with this config? And to recap,
should my server name in the "upstream" directive be the same name in the
"server_name" directive in the "server" stanza?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20160705/271faac4/attachment.html>


More information about the nginx mailing list