Score:0

Config NGINX as proxy for local and remote websites

ie flag
Nil

I got three web servers:

app1 - on local server with nginx. this app listens 127.0.0.1:8080

app2 - on 10.7.0.2:80

app3 - on 10.7.0.10:80

I wan to config NGINX to proxy this three apps on same domain, but different paths:

app1 - https://my.domain.com/something/

app2 - https://my.domain.com/

app3 - https://my.domain.com/nothing/

I have wildcard SSL certificate for *.domain.com

Here is my config:

upstream app2 {
    server 10.7.0.2:80;
}

upstream app3 {
    server 10.7.0.3:80;
}

server {
    listen                 0.0.0.0:80;
    server_name            my.domain.com;
    server_tokens          off;
    return                 301 https://$host$request_uri;
}

server {
    listen                 443 ssl;
    server_name            my.domain.com;
    access_log             logs/my.domain.com main;

    ssl_certificate        /etc/nginx/certs/my.domain.com/cert.txt;
    ssl_certificate_key    /etc/nginx/certs/my.domain.com/private.txt;

    location /something {
        proxy_set_header   Host $host;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass         http://127.0.0.1:8080/;
        include            proxy_params;
    }

    location / {
        proxy_set_header   Host $host;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass         http://app2;
        include            proxy_params;
    }

    location /nothing {
        proxy_set_header   Host $host;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass         http://app3;
        include            proxy_params;
    }
}

But this config works good only for app2.

When i'm trying to open https://my.domain.com/something/ I see this in browser console:

GET https://my.domain.com/styles.css [HTTP/1.1 404 Not Found 265ms]
GET https://my.domain.com/static/js/main.f726536f.js [HTTP/1.1 404 Not Found 432ms]
GET https://my.domain.com/static/css/main.967cebd1.css [HTTP/1.1 404 Not Found 432ms]
Loading failed for the <script> with source “https://my.domain.com/static/js/main.f726536f.js”.

Whats wrong?

us flag
You need to configure your application's root URL properly, so that it creates valid URLs for the resources it loads.
I sit in a Tesla and translated this thread with Ai:

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.