Score:0

How do I configure Nginx proxy to pass to multiple Sinatra ports?

dk flag

I have a Sinatra app. I start two Thin servers listening on: 4567 and 4568. However, I have configured Nginx to only forward to 4567.

server {
        listen 443;
        listen [::]:443;

        root /var/www/example/public;
        index index.html index.htm index.nginx-debian.html;

        server_name example.com www.example.com;

        ssl                        on;
        ssl_certificate        /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key  /etc/letsencrypt/live/example.com/privkey.pem;

        ssl_session_timeout 30m;

        location / {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect off;
                proxy_pass http://localhost:4567;

                proxy_ssl_session_reuse off;
                proxy_set_header Host $http_host;
                proxy_pass_header Server;
                proxy_cache_bypass $http_upgrade;
                proxy_redirect off;

        }
}

server {
    listen      80;
    server_name example.com www.example.com;
    rewrite     ^   https://$server_name$request_uri? permanent;
}

How can I also forward to 4678? I could duplicate the location block, changing only proxy_pass but wouldn't that override the first location block? What is the correct way?

jp flag
Why are you starting two copies of `thin` with the same application on the same host?
Score:2
kr flag

This is called load balancing and is covered in the nginx documentation at http://nginx.org/en/docs/http/load_balancing.html

Here is an example.

http {
upstream myapp1 {
    server srv1.example.com;
    server srv2.example.com;
    server srv3.example.com;
}

server {
    listen 80;

    location / {
        proxy_pass http://myapp1;
    }
}
}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.